gpt4 book ai didi

css - 使用 :not for the first child + every 3 therefore after

转载 作者:行者123 更新时间:2023-12-01 12:54:24 25 4
gpt4 key购买 nike

试图弄清楚如何根据位置攻击某些李。本质上,我需要NOT定位第一个 child ,然后每3个 child 。

示例:

li1 (dont target) | li4(dont target)  | li7 (dont target)
li2 (target) | li5 (target) | li8 (target)
li3 (target) | li6 (target) | li9 (target)

这是我迄今为止尝试过的:

.siteMapSubList. Threecolumn > li:not(:nth-child(1n+3))

类名以及我正在实现的CSS代码都是无关紧要的,所以我没有包含它。然而,这不起作用。例如,不针对我想要定位的目标。我真的试图避免有两个不同的规则(一个不针对第一个 child ,然后每三个 child ),我想我现在可以做到。所以如果可能的话,我真的想在一条规则中做到这一点。

编辑

希望确保人们更好地理解我的需求。因此,本质上,如果我们有 9 li,我不想定位 1、4 和 7。我想定位 2、3、5、6、8、9(这就是我使用 not 运算符的原因,但如果您有更好的方法,我洗耳恭听)。

最佳答案

你们非常接近!您需要的选择器是li:not(:nth-child(3n+1))

参见下面的示例:

ul {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 6em;
}

li {
height: 2em;
}

li:not(:nth-child(3n+1)) {
color: red;
}
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>

关于css - 使用 :not for the first child + every 3 therefore after,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46552268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com