CSS - background color of table row odd/even

后端 未结 9 975

I have a table that is dynamically generated by PHP. I am hoping that I can use CSS to apply a background color based on where the table row is odd/even, i.e. the backgroun

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 08:32

    You can use the nth-of-type() or nth-child() selector in CSS3. Supported by all modern Browsers.

    For example...

    tr:nth-child(odd) { background-color: #ccc; }
    
    /* Do this… */
    tr:nth-of-type(odd) { background-color: #ccc; }
    
    /* …or this */
    tr:nth-of-type(even) { background-color: #ccc; }
    

提交回复
热议问题