讓table 能單雙不同顏色?

想問一下怎麼讓table能不同顏色?
也不是說不同啦
就是

<table>
        <tr>
          <td width="100">a</td>
          <td><a></td>
        </tr>
        <tr>
          <td>b</td>
          <td><b></td>
        </tr>
        <tr>
          <td>c</td>
          <td><c></td>
        </tr>
        <tr>
          <td>d</td>
          <td><d></td>
        </tr>
        <tr>
          <td>e</td>
          <td><e></td>
        </tr>
      </table>

假設這樣

b、d......背景是#eee
雙數都是#eee

阅读 3.5k
4 个回答

对table单数和偶数分别赋值

    table tr:nth-of-type(even) {
        background: #eee;
    }
    
    table tr:nth-of-type(odd) {
        background: #aaa;
    }

css

tr:nth-child(odd) {
    background: red
}
tr:nth-child(even) {
    background: blue
}

table tr:nth-child(odd) {
background-color:#eee;
}
table tr:nth-child(even) {
background-color:#fff;
}

tr:nth-child(odd) {
// 单数
}
tr:nth-child(even) {
background-color: #eee;
}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题