views:

80

answers:

3

I have a <table> that the data is separated per 2 <tr>'s

So i want to style the rows(each 2 rows) as zebra stripped, but each set of 2 should be styled.

I am trying something like:

 tr:nth-child(3n+1), tr:nth-child(4n+1){background:#f7f7f7;}

I would prefer a CSS3 solution, but if only jQuery can do it, that will be fine.

Please see demo here (editable via jsFiddle):

I tried to play around with css-tricks nth-child-tester, but i couldn't get it.

The question is how do i zebra style each set of (2) TR's (rows)

+1  A: 

Would this work for you?

tbody tr:nth-child(4n+1){background:#f00;}
tbody tr:nth-child(4n+2){background:#f00;}
tbody tr:nth-child(4n+3){background:#0f0;}
tbody tr:nth-child(4n+4){background:#0f0;}

This will color pairs of rows alternating as red and green.

Matthew Manela
Thanks much, yes this works, but i would have to do it explicitly for each set.
adardesign
+1  A: 

Here is a fork where every pair of rows is styled.

I had to edit the colour to see anything.

You need to use (4n+1) and (4n+2).

sje397
Thanks, how do i have it start from the second group?now the first 2 are black and skips 2. how do i have it start from 1-2 none, 3-4 black, 5-6 none, 7-8 black.... ?
adardesign
Ok, i got it, `4n+3``4n+4`
adardesign
Thanks much, Like the idea that you forked the original.
adardesign
+1  A: 

Either of these would work:

tr:nth-child(4n+1), tr:nth-child(4n+1)+tr {  }
tr:nth-child(4n+1), tr:nth-child(4n+2) {  }
You
Yea, i like the firs solution, its pretty neat. and it has the least char's. Thanks much.
adardesign