2013-07-11 212 views
1

我目前能夠做讓斑馬錶如下:CSS兄弟姐妹

tbody 
    tr:nth-child(2n+2) 
    background-color: #f3f7f9 

    tr:nth-child(2n+1) 
    background-color: #fff 

    tr.row-headers + tr 
    background-color: #fff 

    tr.row-headers + tr + tr 
    background-color: #f3f7f9 

對於tr.row報頭之後的行,我能夠迫使第一排爲#fff,第二個爲#f3f7f9分別使用「+ tr」和「+ tr + tr」,但我不想爲後面的其餘行執行此操作。我嘗試了第n個孩子(2n + 1)和第n孩子(2n + 2),而不是「+ tr」方法,但這似乎不起作用。有任何想法嗎?

+1

標題聽起來像一個笑話的開始。 :) –

+0

也許答案[這個問題](http://stackoverflow.com/questions/17458582/css-selectors-nth-childeven-odd-with-class/)可以幫助嗎? –

回答

1
tr:nth-child(even) { background-color: #fff; } 

tr:nth-child(odd) { background-color: #f3f7f9; } 

這就是你所追求的?

Live example

或其他語法:

tbody 
    tr:nth-child(even) 
    background-color: #f3f7f9 

    tr:nth-child(odd) 
    background-color: #fff