Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nth-child to alternate by 2 rows [duplicate]

I want to use CSS3's nth-child selector to alternate between background color two rows thick, rather than the usual one row when using nth-child(odd).

The "Result" section of this jsFiddle illustrates what I want.

So we would have a table:

ROW 1: Blue
ROW 2: Blue
ROW 3: Red
ROW 4: Red
ROW 5: Blue
ROW 6: Blue
like image 911
John 'Mark' Smith Avatar asked Apr 10 '14 16:04

John 'Mark' Smith


1 Answers

You can use this:

tr {
    background: blue;
}

tr:nth-child(4n+1), tr:nth-child(4n+2) {
    background: red;
}

n will count from 0 and up.

DEMO

like image 185
Mathias Avatar answered Nov 18 '22 19:11

Mathias