Debugging nth-child selector

Posted by Ross on Stack Overflow See other posts from Stack Overflow or by Ross
Published on 2010-03-23T21:05:06Z Indexed on 2010/03/23 21:23 UTC
Read the original article Hit count: 399

Filed under:
|
|

I have the following selectors:

.progress:nth-child(3n+1) {
    background: teal;
}

.progress:nth-child(3n+2) {
    background: red;
}

.progress:nth-child(3n+3) {
    background: blue;
}

However all of the items end up with a teal background. Are these selectors correct? I'm thinking I should get:

  1. Teal (every 3, starting with 1)
  2. Red (every 3, starting with 2)
  3. Blue (every 3, starting with 3) etc.

I've tested on Firefox 3.5.8 and Opera 10.10 on Ubuntu. Also tested with nothing but these rules in the CSS. I'm using the YUI Reset stylesheet but excluding it does nothing.

© Stack Overflow or respective owner

Related posts about css

Related posts about nth-child