How to create zebra stripes on html table without using javascript and even/odd classes generation?

后端 未结 5 1526
情话喂你
情话喂你 2020-12-08 01:54

I want to zebra-stripe a html table without using any js stuff or writing server-side code to generate even/odd classes for table rows. Is it ever possible to do using raw c

5条回答
  •  情话喂你
    2020-12-08 02:25

    It is possible, with CSS3 selectors:

    tr:nth-child(even) {
      background-color: red;
    }
    
    
    tr:nth-child(odd) {
      background-color: white;
    }
    

    According to caniuse.com, every browser supports it now.

提交回复
热议问题