CSS :not(:last-child):after selector

Matt Clarkson picture Matt Clarkson · Mar 27, 2011 · Viewed 551.7k times · Source

I have a list of elements, which are styled like this:

Outputs One | Two | Three | Four | Five | instead of One | Two | Three | Four | Five

Anyone know how to CSS select all but the last element?

You can see the definition of the :not() selector here

Answer

imma picture imma · Mar 16, 2012

If it's a problem with the not selector, you can set all of them and override the last one

li:after
{
  content: ' |';
}
li:last-child:after
{
  content: '';
}

or if you can use before, no need for last-child

li+li:before
{
  content: '| ';
}