如何调整以下CSS选择器:
.myTableRow td:nth-child(?){ background-color: #FFFFCC; }
所以它适用于TD列2-4?
<table> <tr class="myTableRow"> <td>column 1</td> <td>column 2</td> <td>column 3</td> <td>column 4</td> <td>column 5</td> </tr> </table>
您将无法一次完成此操作:nth-child()-您将需要链接至少一个其他此类伪类。例如,的组合:nth-child()和:nth-last- child()(该n+2位装置开始从第二子分别计数向前和向后):
:nth-child()
:nth-last- child()
n+2
.myTableRow td:nth-child(n+2):nth-last-child(n+2){ background-color: #FFFFCC; }
或者,不使用公式,只需排除:first-child和:last-child:
:first-child
:last-child
.myTableRow td:not(:first-child):not(:last-child){ background-color: #FFFFCC; }