Reputation: 8701
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>
Upvotes: 6
Views: 7466
Reputation: 10686
You can use the following formula:
:nth-child(n+1)
or for some browsers:
:nth-child(n+2)
W3Schools says:
Using a formula (an + b). Description: a represents a cycle size, n is a counter (starts at 0), and b is an offset value.
Or you can use separate :first-child
CSS declaration for this first element.
Upvotes: 13