Daniel
Daniel

Reputation: 1675

CSS selector for other than the first child and last child

I am making a very advanced website. My question: Is it possible to select all the other children except for the :first-child and the :last-child? I know there is a :not() selector but it doesn't work with more than one not in the parentheses. This is what I have:

#navigation ul li:not(:first-child, :last-child) {
    background: url(images/[email protected]);
    background-size: contain;
}

Upvotes: 167

Views: 115449

Answers (2)

Celmaun
Celmaun

Reputation: 24752

Try:

#navigation ul li:not(:first-child):not(:last-child) {
  ...
}

Upvotes: 376

animuson
animuson

Reputation: 54719

Sure it will work, you just have to use two 'not' selectors.

#navigation ul li:not(:first-child):not(:last-child) {

It will continue down the line after the first one, saying "not the first child" and "not the last child".

Upvotes: 28

Related Questions