我想在这样的表格中设置th和td元素的样式:
<table>
<tr>
<th>Abc</th>
<td>Cde</td>
</tr>
<tr>
<th>Abc</th>
<td>Cde</td>
</tr>
</table>我不想给它添加类,所以我需要这样做:
tr td, tr th{background:#dddddd;}
tr:nth-child(even) td, tr:nth-child(even) th{background:#ffffff;}但是..。这样做有什么缺点吗?
tr > *{background:#dddddd;}
tr:nth-child(even) > *{background:#ffffff;}发布于 2017-02-02 17:41:41
不,在最坏的情况下,你只会被那些仍然坚持“避免通用选择器”教条的人叫嚷。如果您仍然担心,因为您的页面极其复杂,有数千个元素,那么您可以选择不使用它,但您只能凑合使用扩展的选择器列表,因为there isn't any cross-browser alternative available。
https://stackoverflow.com/questions/41998054
复制相似问题