HTML 同时悬停 img 和文本

标签 html css image hover

需要在 img 上添加边框颜色,并在悬停时为下方的文本添加相同的颜色。

谢谢!

最佳答案

使用 + 选择器选择一个元素 after 一个带有 :hover 伪类的元素:

img:hover {
    border: thick red solid;
}

img:hover + figcaption {
    color: red;
}
<figure>
  <img src="http://placehold.it/350x150" />
  <figcaption>Caption goes here</figcaption>
</figure>

同样的事情,但是 HTML 结构和你的一样:

img:hover {
    border: thick solid green;
}

a:hover + h5 a {
    color: green;
}
<div class="prod">
  <a href="http://">
     <img class="size-full wp-image-682 aligncenter" src="http://placehold.it/350x150" />
  </a>
  <h5 style="text-align: center; margin-top: 15px; text-transform: uppercase; color: #727176;">
    <a href="a/">Letters</a>
  </h5>
</div>

关于HTML 同时悬停 img 和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43691852/

相关文章:

html - 我的缩略图的 CSS 问题

css - 绝对位置,限制其大小

c# - 如何强制平滑呈现 WPF 控件?

java - 是否可以在 Eclipse 中显示图像直方图

java - 如何通过 Java 小程序将图像文件保存在服务器上?

html - bootstrap - 将不同宽度的多列居中

php - PHP和HTML代码的结构

javascript - 在点击提交时填充一个隐藏字段

php - 如何在php中改变颜色

html - 为什么在附加到我的标签的 CSS 类中设置宽度不会改变它们的宽度?