Css悬停,父母和孩子 [英] Css hover, parent and child
本文介绍了Css悬停,父母和孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下代码:
Let's say i have the following code:
<div class="wrapper">
<div class="title"></div>
<div></div>
</div>
<div class="wrapper">
<div class="title"></div>
<div></div>
</div>
<div class="wrapper">
<div class="title"></div>
<div></div>
</div>
将鼠标悬停在包装上时,我希望它是 title div来改变它的背景颜色。
我可以在纯CSS中执行此操作吗?在js我知道如何去做。我感兴趣的是,如果存在一个纯粹的CSS方法吗?
On hover for a wrapper I want it's child title div to change it's background color. Can I do this in pure css. In js I know how to do it. I'm interested if a pure CSS method exists for this?
谢谢
Thanks
推荐答案
是的,你可以做到这一点。它只是:
yes, you can do this. it's just:
.wrapper:hover .title{
background-color: #f00;
}
编辑:
请注意,IE6仅在 a
-elements上识别:hover
,所以这不起作用 - 但我希望你不必捣乱那个蹩脚的旧东西。
please note that IE6 recognizes :hover
only on a
-elements, so this won't work - but i hope you don't have to mess with that crappy old thing.
这篇关于Css悬停,父母和孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文