类型的n,除了标头

永远怀疑

我有以下代码用于更改表格中的单元格颜色。我想保持这种行为,但不包括标题行,由于第n个类型为奇数的命令,该行当前为橙色。

tr:nth-of-type(even) { 
            background: green; 
            color: white; 
            font-weight: bold; 
            width: 70%; 
        } 
tr:nth-of-type(odd) { 
            background: orange; 
            color: white; 
            font-weight: bold; 
            width: 70%; 
        } ```
米海

您可以使用:not选择器跳过第一个孩子(标头)

还有其他解决方案

tr:nth-of-type(even) {
  background: green;
  color: white;
  font-weight: bold;
  width: 70%;
}

tr:nth-of-type(odd):not(:first-child) {
  background: orange;
  color: white;
  font-weight: bold;
  width: 70%;
}
<table>
<tr><td>header</td></tr>
<tr><td>other</td></tr>
<tr><td>other</td></tr>
<tr><td>other</td></tr>
<tr><td>other</td></tr>
<tr><td>other</td></tr>
<tr><td>other</td></tr>
</table>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章