Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude last child in css pseudo class selector

I want to apply a particular style for child div from 4 to n-1 .i was able to do from 4 to n , but could not exclude the last div

here is the jsfiddle http://jsfiddle.net/8WLXX/

.container div:nth-child(n+4)   {     background: red; }

All I want is exclude last div also.

like image 384
NewtonCode Avatar asked Nov 12 '13 12:11

NewtonCode


2 Answers

You can do this:

.container div:nth-child(n+4):not(:last-child) {
    background: red;
}

Fiddle Demo

like image 57
palaѕн Avatar answered Oct 23 '22 14:10

palaѕн


Simply add :not(:last-child) to the selector:

.container div:nth-child(n+4):not(:last-child)
like image 24
Jon Avatar answered Oct 23 '22 15:10

Jon