Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip first child?

<div id="main">       <p> one </p>       <p> two </p>   <p> three </p>   <p> four </p>   <p> five </p> <div> 

I don't want to apply css on first <p>One</p>

p {color:red} 

I need just opposite of :first-child.

like image 452
Jitendra Vyas Avatar asked May 18 '10 08:05

Jitendra Vyas


People also ask

How do I skip the first child in CSS?

I think :nth-child() will do the trick. This styles all of the p tags except for the first because it starts on the 2nd child. You could then style the first p tag separately with p:first-child .

How do you not use your first child?

ul:not(:first-child) means literally "any ul element that is not first child of its parent", so it won't match even the 1st ul if it's preceded by another element ( p , heading etc.). On the contrary, ul:not(:first-of-type) means "any ul element except the 1st ul in the container".

How do you not choose your last child?

The :not() selector excludes the element passed to it from selection. The :last-child selector selects the last child. Combining these two above selector to excludes the last children (inner-div) of every parent div from the selection.


1 Answers

With the negation pseudo-class:

p:not(:first-child) { color: red; } 

Browser support is very strong now, but alternatives include:

p { color: red; } p:first-child { color: black; } 

and:

* + p { color: red; } 
like image 78
Quentin Avatar answered Oct 15 '22 03:10

Quentin