How to alternate HTML table row colors using JSP?

后端 未结 6 1516
你的背包
你的背包 2020-12-05 17:35

How do I alternate HTML table row colors using JSP?

My CSS looks something like:

tr.odd {background-color: #EEDDEE}
tr.even {background-color: #EEEED         


        
6条回答
  •  情歌与酒
    2020-12-05 18:06

    (this answer only pertains to the CSS side of things...)

    As a matter of course, I always target the child TD's like so:

    tr.odd td {}
    tr.even td {}
    

    The reason being is that IE actually applies TR background-color by removing the value set on the TR and applying it to each individual TD within that TR. Sometimes you might have a css reset or other css rules that overrides IE's strange way of doing TR background-color, so this is a way to make sure you avoid that.

    Also, you might want to consider setting just

    tr td {background-color: #EEDDEE}
    

    and

    tr.odd td {background-color: #EEEEDD}
    

    so your code is slightly less verbose

提交回复
热议问题