Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select all children of an element except the last child?

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).

like image 492
RyanScottLewis Avatar asked Apr 04 '10 04:04

RyanScottLewis


People also ask

How do I use except last child in CSS?

There is a:not selector in css3. Use :not() with :last-child inside to select all children except last one.

How do I select every child except first?

This selector is used to select every element which is not the first-child of its parent element. It is represented as an argument in the form of :not(first-child) element.


1 Answers

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 */ } 
like image 191
Nick Craver Avatar answered Sep 22 '22 23:09

Nick Craver