选择特定父级的子元素

时间:2013-09-09 06:23:48

标签: html css

我在body标签的每一页都有不同的类,我在body标签中使用css作为#top div

<body class="one">
<div id="top"></div>
</body>

#top{
  /*css code here*/
}

我想使用相同的css而不是类.one这样的东西:

#top:not(.one){
/*css code here*/
}

更清楚我想对#top的所有页面应用相同的css但不要对body类为.one

的页面应用相同的css

1 个答案:

答案 0 :(得分:0)

使用父级的:not选择器,而不是孩子。

body:not(.one) #top {
    /*css code here*/
}
  • P.S - 你应该注意到这个选择器有一些浏览器支持问题,你可以看到here