问题:
I would like to write a CSS selector rule that selects all elements that don't have a certain class. 我想编写一个CSS选择器规则,选择所有没有特定类的元素。 For example, given the following HTML: 例如,给定以下HTML:
<html class="printable">
<body class="printable">
<h1 class="printable">Example</h1>
<nav>
<!-- Some menu links... -->
</nav>
<a href="javascript:void(0)" onclick="javascript:self.print()">Print me!</a>
<p class="printable">
This page is super interresting and you should print it!
</p>
</body>
</html>
I would like to write a selector that selects all elements that don't have the "printable" class which, in this case, are the nav and a elements. 我想编写一个选择器来选择所有没有“可打印”类的元素,在这种情况下,它是nav和元素。
Is this possible? 这可能吗?
NOTE: in the actual HTML where I would like to use this, there are going to be a lot more elements that don't have the "printable" class than do (I realize it's the other way around in the above example). 注意:在我想要使用它的实际HTML中,将会有更多的元素没有 “可打印”类而不是(我在上面的例子中意识到它是另一种方式)。
解决方案:
参考一: https://stackoom.com/question/cE0K/我可以编写一个CSS选择器来选择不具有某个类或属性的元素吗参考二: https://oldbug.net/q/cE0K/Can-I-write-a-CSS-selector-selecting-elements-NOT-having-a-certain-class-or-attribute
来源:oschina
链接:https://my.oschina.net/u/4428122/blog/4407014