我想在父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>
最佳答案
使用 CSS 你可以做到这一点:
.parent:hover .child, .parent.hover .child { background: green; }
以下是更新后的代码:http://jsfiddle.net/bCkpb/17/
关于html - 悬停在父 div 上时更改子 div 的背景颜色吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49086312/