如何使用 :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.
或者您可以为第一个元素使用单独的 :first-child
CSS 声明。
关于html - 如何用 nth-child 定位第一个元素以外的所有元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12193104/