我试图弄清楚为什么当鼠标悬停在类 'a' 上时类 'b' 的背景没有改变,就像在这个问题中一样。我怎样才能让它发挥作用?我也希望它与 a 标签一起使用。
谢谢你的帮助!
.a {
width: 200px;
height: 200px;
background: orange;
}
.b {
background: lightgreen;
}
.a:hover + .b {
background: #ccc;
}
<div class='a'>
<span class='b'>here</span>
<span class='b'><a href='http://www.google.com'>here</a></span>
</div>
您使用了错误的选择器,您应该使用直接子组合器,或者>
因为span
's 在 内div
:
.a {
width: 200px;
height: 200px;
background: orange;
}
.b {
background: lightgreen;
}
.a:hover > .b {
background: #ccc;
}
<div class='a'>
<span class='b'>here</span>
<span class='b'><a href='http://www.google.com'>here</a></span>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句