html - 悬停在父 div 上时更改子 div 的背景颜色吗?

标签 html css

我想在父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/

最佳答案

使用 CSS 你可以做到这一点:

.parent:hover .child, .parent.hover .child { background: green; }

以下是更新后的代码:http://jsfiddle.net/bCkpb/17/

关于html - 悬停在父 div 上时更改子 div 的背景颜色吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49086312/

相关文章:

html - div自动响应里面的文字

jquery - 是否有任何方法或程序可以防止 jQuery 应用除当前类之外的所有相同类?

jquery - 尽管加载了 'Slick' Carousel jQuery 插件的 CSS 不影响我的 DOM

html - CSS Clear取决于元素的奇数或偶数

html - 奇怪的 :hover behavior when using rowspan

javascript - 使用javascript验证注册表单

javascript - 数据表刷新按钮和旋转很棒的图标

html - carousel-inner 内的按钮不可点击

javascript - 如何在不使用路径元素坐标的情况下在 React 中的 SVG 路径元素上叠加文本?

html - 如何居中对齐表格