我需要根据奇数/偶数改变td的文本颜色,比如http://jsfiddle.net/N9gEG/
实际上我有一个类这样做,但是,我想用css做
<table>
<tr>
<td>RED</td>
<td class="foo">BLUE</td>
<td>RED</td>
<td class="foo">BLUE</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
对于tr奇数/偶数,我有以下代码:table tr:nth-child(even).
td {
color: blue;
}
td:nth-child(even) {
color: red;
}
Run Code Online (Sandbox Code Playgroud)
这是因为规则特异性.更具体的CSS规则获胜.td没有其他任何东西没有特定的td:nth-child(even),所以它<td>自动适用于奇数s.