我想在父 div 悬停时更改子 div 的背景颜色。目前,我可以更改颜色,但只能将鼠标悬停在子 div 上。但是,我也想更改父 div 悬停时的颜色。
<div class="content">
<div class="logo">Button</div>
</div>
<style>
.content {
position:relative;
margin:0 auto;
width:300px; height:250px;
background-color:blue;
overflow: hidden;
}
.logo {
margin:50px auto;
background:yellow;
text-align:center;
}
.logo:hover {
background: red;
}
</style>
看看这个:http://jsfiddle.net/bCkpb/10/ http://jsfiddle.net/bCkpb/10/
使用CSS你可以这样做:
.parent:hover .child, .parent.hover .child { background: green; }
这是更新后的代码:http://jsfiddle.net/bCkpb/17/ http://jsfiddle.net/bCkpb/17/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)