How would I select all but the last child using CSS3 selectors?

For example, to get only the last child would be div:nth-last-child(1).

10 Answers
10

You can use the negation pseudo-class :not() against the :last-child pseudo-class. Being introduced CSS Selectors Level 3, it doesn’t work in IE8 or below:

:not(:last-child) { /* styles */ }

Leave a Reply

Your email address will not be published. Required fields are marked *