是否有人知道如何使用CSS选择器:not()
作为#some_id:not(.any_class_name)
?
代码看起来好像是正确的,但它不起作用.没有not
选择器还有另一种方法吗?我在网上找不到任何东西.
我正在制作一个Web应用程序,其中包含多个页面,但有几个页面有div id=some_id
.我以为我必须通过any_class_name
使用上面的CSS代码添加一次来添加特定的CSS来解决问题,但它不起作用.
我相信你正在扭转选择者.您有一些相同的元素class
,但您想过滤掉具有特定元素的元素ID
.在这种情况下:
HTML:
<p class="someclass">hello</p> <!-- will be targeted by css below, thus green --> <p class="someclass" id="some-id">hi</p> <!-- will not be targeted by css below -->
CSS:
.someclass:not(#some-id){ color: green; } /* selects all elements with classname 'someclass', but excludes the one that has also has an id of 'some-id' */
正如@secretSquirrel指出的那样,请注意浏览器兼容性:Internet Explorer 8及更早版本不支持此选择器.