Make alternating CSS table row style work in Internet Explorer

后端 未结 3 979
夕颜
夕颜 2020-12-09 11:35

I use this CSS code to display a database output in rows where the colors repeat in every 2nd row

tbody tr:nth-child(2n) td, tbody tr.even td {  
    backgro         


        
相关标签:
3条回答
  • 2020-12-09 12:00

    I like the answer above, but alternate row colours doesn't seem to work if a document isn't refreshed.

    Try jQuery too:

    $("tbody tr:even td").css("background-color", "lightgray");
    

    Link:
    http://docs.jquery.com/Tutorials:Zebra_Striping_Made_Easy

    0 讨论(0)
  • 2020-12-09 12:02

    Which version of IE are you using? the :nth-child() CSS won't work in old versions of IE.

    IE6, IE7, IE8 Fail

    IE9 (works)

    0 讨论(0)
  • 2020-12-09 12:18

    IE8 does not support the :nth-child CSS property. You can make it work in IE8 with this script:

    https://github.com/roylory/ie7-js

    How to use it:

    You can Include it via conditional comments, e.g.:

    <!--[if lte IE 9]>
    <script src="IE9.js"></script>
    <![endif]-->
    

    The script will only load in IE9 and below, other browsers do not see it.

    Live demo: https://jsbin.com/koyahe/edit?html,css,output

    (This demo should work in all versions of IE.)

    0 讨论(0)
提交回复
热议问题