如何在父元素和子元素上设置CSS悬停效果 [英] How to set CSS hover effect, on parent and child elements
本文介绍了如何在父元素和子元素上设置CSS悬停效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下代码:
<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?
谢谢
推荐答案
是的,您可以执行此操作.只是:
Yes, you can do this. It's just:
.wrapper:hover .title {
background-color: #f00;
}
请注意,IE6仅在a
元素上识别: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屋!
查看全文