<分区>
标签 html css css-selectors
<分区>
我正在尝试选择除前 3 个之外的所有“类”类。我不确定为什么我的语法不正确。有人可以解释我在这里做错了什么吗?
我尝试了一些不同的组合,比如在第 n 个类型之前在选择器中包含类名,以及其他组合。
.classes {
background: red;
width: 200px;
height: 30px;
margin-bottom: 5px;
}
.classes:not(.classes:nth-of-type(1)), .classes:not(nth-of-type(2)), .classes:not (nth-of-type(3)) {
background: blue;
}
.classes:nth-of-type(6) {
background: orange;
}
<div class='classes'>test</div>
<div class='classes'>test</div>
<div class='classes'>test</div>
<div class='classes'>test</div>
<div class='classes'>test</div>
<div class='classes'>test</div>
<div class='classes'>test</div>
最佳答案
你可以使用这个:
.classes {
background: green;
}
.classes:nth-child(n+4) {
background: red;
}
您可以找到更有用的 :nth-child
示例 here
如果你想完全使用 :not 选择器,你可以试试这个:
.classes:not(:first-child):not(:nth-child(2)):not(:nth-child(3)) {
background: yellow;
}
关于html - 使用 :not(selector) 选择除少数元素之外的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50249367/