我可以编写一个CSS选择器来选择不具有某个类或属性的元素吗?

倖福魔咒の 提交于 2020-08-18 07:45:12

问题:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!