本文介绍了如何针对除第一个孩子之外的所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用:nth-​​child 运算符将给定DIV中除第一个段落外的所有段落作为目标?

How do I target all paragraphs inside a given DIV beside the first one using the :nth-child operator?

: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说:

W3Schools says:

链接

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

Or you can use separate :first-child CSS declaration for this first element.

这篇关于如何针对除第一个孩子之外的所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 01:33
查看更多