<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
.
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 .
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".
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.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With