0

我在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

4

1 回答 1

0

在父级上使用:not选择器,而不是在子级上。

body:not(.one) #top {
    /*css code here*/
}
  • PS-你应该注意到这个选择器有一些浏览器支持问题,你可以在这里看到。
于 2013-09-09T06:27:08.393 回答