user2581346
user2581346

Reputation:

More than One Nth-Child

Can I use more than one nth-child selctor for a class?

For example,

.span4:not(nth-child(1)):nth-child(3n+1) {
  background-color: red
}

I want to target the 4th, 7th, 10th, etc., except the 1st one.

If there's a better way of doing this, please let me know.

Thanks guys!

Upvotes: 0

Views: 1705

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201538

You can use the combined selector :not(nth-child(1)):nth-child(3n+1), but it is easier and simpler to use :nth-child with an argument that matches the children you wish to match, in this case :nth-child(3n+4).

Upvotes: 2

Joseph Silber
Joseph Silber

Reputation: 219920

You're missing a colon before nth-child:

           |
.span4:not(:nth-child(1)):nth-child(3n+1) {
    background-color: red
}

Here's the fiddle: http://jsfiddle.net/7hcY2/

Upvotes: 1

Related Questions