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

标签 html css css-selectors

如何使用 :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/

相关文章:

javascript - 编写额外的 </div> 标记,Blogger 不会自动更正它

html - 如何更改数据列表的显示宽度

html - 如何通过 "for"属性更新 Prototype 中 <label> 的 innerHTML?

html - 具有线性渐变的三 Angular 形中的 CSS 颜色过渡

html - 下面的 CSS 可以进一步简化吗?

javascript - 尝试调用 jQuery 设置的 onchange 方法

css - 如何添加 webkit-keyframes 动画延迟

css - Bootstrap Accordion 在 safari 中出现奇怪的弹跳

python - 如何使用python在selenium中通过部分id名称查找元素

jQuery find $.find ('selector' ) 与 $ ('selector' ) 区别