CSS - background color of table row odd/even

后端 未结 9 963

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:50

    You can do something like this:

    $counter = 0;
    while(............){
      $counter++;
    
      $bgcolor = ($counter % 2 === 0) ? 'red' : 'blue';
    
    }
    

    Now you can use bgcolor="" for your TDs :)

    Note that above will work in all browsers including IE6.

提交回复
热议问题