2016-08-22 92 views

回答

2

您應該使用第n個孩子:

 
tr:nth-child(odd) { 
    background: green; 
} 

tr:nth-child(even) { 
    background: lightgreen; 
} 

:odd:even是jQuery的僞元素選擇不是CSS。

1

tr:nth-child(even) {background: red} 
 
tr:nth-child(odd) {background: green}
<table> 
 
    <tr class="d0"> 
 
    <td>one</td> 
 
    </tr> 
 
    <tr class="d1"> 
 
    <td>two</td> 
 
    </tr> 
 
    <tr class="d1"> 
 
    <td>two</td> 
 
    </tr> 
 
    <tr class="d1"> 
 
    <td>two</td> 
 
    </tr> 
 
</table>

0

\t tr:nth-child(odd) { 
 
\t background-color: green; 
 
\t } 
 
\t 
 
\t tr:nth-child(even) { 
 
\t background-color: lightgreen; 
 
\t }
<table> 
 
<tr><td>1</td></tr> 
 
<tr><td>1</td></tr> 
 
<tr><td>1</td></tr> 
 
<tr><td>1</td></tr> 
 
<tr><td>1</td></tr> 
 
</table>

使用所有的標籤<table><td>。還用:nth-child(odd):nth-child(even)代替:odd:even
這是我的JSFiddle:https://jsfiddle.net/v2tgjLjv/9/

相關問題