html - 子元素悬停,影响父元素

标签 html css hover css-selectors

我知道如何制作“父悬停,子 Action ”

.parent:hover > .child{background:#a4d186;}

但如果可能的话我想要这个:

.parent < .child:hover{blabla}

最佳答案

目前还没有这样的选择器,但您可以使用“~”选择器。 以下是 w3.org

的摘录

The general sibling combinator is made of the "tilde" (U+007E, ~) character that separates two sequences of simple selectors. The elements represented by the two sequences share the same parent in the document tree and the element represented by the first sequence precedes (not necessarily immediately) the element represented by the second one.

所以你可以这样做:

HTML:

<div class="parent-like-div">Do Something</div>
<div class="to-be-controlled">Control me</div>

CSS:

.parent-like-div:hover ~ .to-be-controlled
{your code apply on .to-be-controlled when you hover .parent-like-div}

http://jsfiddle.net/h7grfeod/

关于html - 子元素悬停,影响父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25601089/

相关文章:

html - CSS - 页眉 - 始终底部页脚和 100% 内容

html - 删除 HTML、CSS 中按钮之间的空格

jQuery 高级悬停和淡入功能

html - 如何在 css 中创建自定义复选框

html - div不适用于整个表格

html - postMessage 不工作

javascript 使用复选框迭代对象数组

javascript - 我如何解决这个最大高度 Javascript 问题或使用 CSS 获得相同的结果?

css - 将目标 ="_blank"用于 anchor 不再返回 html5 文档类型中的验证错误

jquery - 如何使用 jquery 使该选项卡具有动画效果?