user828591
user828591

Reputation: 1262

CSS-Selector :child(> n)?

I got the problem that I got a variable amount of child-elements. My :last-child :first-child rules should only apply, when there are at least 3 children

I tried :only-child, which can overwrite :last- and :first-child when there is only 1 child, but when I got 2 children, I have a problem. Is there some sort of selector, that only applies, when there are more children than n?

Upvotes: 10

Views: 7705

Answers (1)

Rob W
Rob W

Reputation: 348992

Use the :nth-child(n+3) selector (where 3 is the nth minimum child).

:last-child:nth-child(n+3) {
     /* Selects the last child which is at least the third child */
}

Demo: http://jsfiddle.net/vCZ9A/

Upvotes: 23

Related Questions