html – 影响div:悬停与另一个div

前端之家收集整理的这篇文章主要介绍了html – 影响div:悬停与另一个div前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > How to affect other elements when a div is hovered6个
我正在制作一个画廊,当你将鼠标悬停在主图像上时,缩略图应该变得透明.我想用纯CSS实现这一点,但我不确定这是否可行.

CSS:

/* should affect thumbs but not main */
/* obvIoUsly this code wouldn't work */
#main:hover,#thumbs {
  opacity: .5;
}

HTML:

<div id="main">
  Hover over me to change #thumbs
</div>
<div id="thumbs">
  I change when you hover over #main
</div>

这可能使用纯CSS吗?

解决方法

当然,只需使用相邻的兄弟选择器:
#div1:hover + #div2 {
    ...
}

这里有一个例子:http://jsfiddle.net/6BfR6/94/

原文链接:https://www.f2er.com/html/227633.html

猜你在找的HTML相关文章