每个'tr'都有不同的背景颜色

时间:2014-08-27 05:59:25

标签: css css3

我的tr HTML下面有table列表:

<table>
  <tr>
    <td>content here</td>
    <td>content here</td>
    <td>content here</td>
  </tr>
  <tr>
    <td>content here</td>
    <td>content here</td>
    <td>content here</td>
  </tr>
  <tr>
    <td>content here</td>
    <td>content here</td>
    <td>content here</td>
  </tr>
  <tr>
    <td>content here</td>
    <td>content here</td>
    <td>content here</td>
  </tr>
</table>

是否可以使用css为每个tr设置不同的背景颜色,例如使用nth-child

我试试这个:

    table tr:nth-child(1) {
      background-color:#000
    }

但它不起作用。

2 个答案:

答案 0 :(得分:1)

试试这个:

tr:nth-child(2n+1){
   background-color:#000;
}

答案 1 :(得分:0)

你可以这样做:

table tr:nth-child(1)>td {
  background-color:#000
}
相关问题