鍍金池/ 問答/HTML5  PHP  HTML/ 讓table 能單雙不同顏色?

讓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

回答
編輯回答
葬愛

css

tr:nth-child(odd) {
    background: red
}
tr:nth-child(even) {
    background: blue
}
2017年10月17日 11:32
編輯回答
哎呦喂

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

2017年2月3日 17:18
編輯回答
朕略傻

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

2018年7月1日 08:57
編輯回答
野橘

對table單數和偶數分別賦值

    table tr:nth-of-type(even) {
        background: #eee;
    }
    
    table tr:nth-of-type(odd) {
        background: #aaa;
    }
2018年4月15日 14:50