gpt4 book ai didi

html - 如何用 nth-child 定位第一个元素以外的所有元素?

转载 作者:太空狗 更新时间:2023-10-29 14:41:53 26 4
gpt4 key购买 nike

如何使用 :nth-child 运算符定位给定 DIV 内除第一个段落之外的所有段落?

:nth-child(/* select all but the first one */) {
color: green;
}
<div>
<p>Example 1</p>
<p>Example 2</p>
<p>Example 3</p>
<p>Example 4</p>
<p>Example 5</p>
<p>Example 6</p>
<p>Example 7</p>
</div>

最佳答案

您可以使用以下公式:

:nth-child(n+1)

或者对于某些浏览器:

:nth-child(n+2)

W3Schools 说:

Using a formula (an + b). Description: a represents a cycle size, n is a counter (starts at 0), and b is an offset value.

Link

或者您可以为第一个元素使用单独的 :first-child CSS 声明。

关于html - 如何用 nth-child 定位第一个元素以外的所有元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12193104/

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