可能重复: 有CSS父选择器吗?
我可以使用.closest()隐藏一个DOM树,它以这种方式看上去。
<div class='parent'>
<!-- some html code -->
<div class='child'>
</div>
<!-- some html code -->
<div>
$('.child').closest('parent').hide();使用CSS就可以达到同样的效果吗?
如果是,怎么做?
发布于 2012-10-03 13:18:55
当前不存在可以选择以前元素或父元素的选择器。
有一个级别4的选择器,即目前正在开发中。
所以在未来,你可能会做这样的事情:
!.parent > .child { display: none; }但在那之前,你必须坚持
$('.child').parent();在jQuery中。
发布于 2012-10-03 13:09:24
不是的。亲眼目睹,在CSS3中不存在这样的选择器,在CSS2也是中不存在。
发布于 2012-10-03 13:01:18
也许能用这个
.child:parent .parent{display:none;}http://css-tricks.com/parent-selectors-in-css/
https://stackoverflow.com/questions/12709004
复制相似问题