[英]How to style child's child element when hover over parent
I'm trying to style span .m_12
on hover over .box_1 img
using .box_1 img:hover ~ .m_12
.But this seems not working. 我正在尝试使用
.box_1 img:hover ~ .m_12
在.box_1 img
.box_1 img:hover ~ .m_12
span .m_12
为样式。但这似乎不起作用。
<div class="col-md-4 box_1">
<a href="#">
<img src="images/pic1.jpg" class="img-responsive" alt=""/>
</a>
<div class="box_2">
<div class="special-wrap">
<div class="forclosure2">
<span class="m_12">$140</span>
</div>
</div>
</div>
</div>
This 这个
.box_1 img:hover ~ .m_12
will not work because it assumes that .m_12
is a sibling of the img
and it isn't. 将不起作用,因为它假定
.m_12
是img
的同级兄弟,而不是。
Hovering can only affect the element being hovered, it's descendents or siblings. 悬停只会影响被悬停的元素,即后代或兄弟姐妹。
So, you would need. 因此,您将需要。
.box_1 a:hover + .box_2 .m_12
or 要么
.box_1 a:hover ~ .box_2 .m_12
In other words, the .m_12
element is a child/descendant of .box2
which is a sibling of the link a
which is a child of .box_1
换句话说,所述
.m_12
元件是的子/后代.box2
其是链路的兄弟 a
其的子.box_1
use this code: 使用此代码:
.box_1 img:hover .m_12 {
/* Write your style */
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.