关注焦点父元素的风格
这个问题在这里已经有了答案:
在CSS(还没有)中没有父选择器。 http://css-tricks.com/parent-selectors-in-css/
但是,您可以使用jQuery选择它:
HTML
<div class="parent">
<input type="text" />
</div>
CSS
.parent {
/* parent styles */
}
.parent.active {
/* do stuff when the input is hovered */
}
JS
// listen for a focus event on the input,
// and then add a class to the parent
$('input').on('focus', function () {
$(this).parent().addClass('active');
});
http://jsfiddle.net/M64nv/
不。在CSS中没有父级选择器,所以当其中一个子元素被徘徊时(或基于任何子元素条件),您不能在父元素上触发样式规则。 你需要为此使用Javascript。
链接地址: http://www.djcxy.com/p/22831.html上一篇: style on focused parent element
下一篇: Change radio button label's color when radio button is selected?