<分区>
标签 css
<分区>
我正在尝试定位 h 标签的所有实例,但仅当它没有类时。
例如:
<h1 class="class1">First</h1>
<h1 class="class2">Second</h1>
<h1>Third</h1>
在这种情况下,我只想定位 Third 而不是其他 - 我找到了一个答案 ( Is there a CSS selector for element without any class? ),它提到了 [class=""] 选择器,但似乎只适用于:
<h1 class="">Third</h1>
遍历并列出类的所有实例,然后使用 :not 引用它们是不切实际的,那么还有其他方法吗?
我承认在某些 h1 类的当前 CSS 中使用 !important 等会使情况变得更糟,但我继承了这一点,我没有能力从头开始。
最佳答案
if you use h1: not ([class]) this tag search all.
如果有很多 !important 你应该在新的 css 中使用它并且这个新的 css 将它放在所有 .css 的末尾
Example:
<h1 class="class1">First</h1>
<h1>Second</h1>
<h1>Third</h1>
h1:not([class]) {
color: red;
}
关于元素没有类时的 CSS 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54468956/