Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make alternating CSS table row style work in Internet Explorer

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 {  
    background: none repeat scroll 0 0 #E5ECF9;  
}

If I open it in my IE it won't work. Any advice?

I am using IE 8.

like image 699
daniel Avatar asked Jan 20 '11 00:01

daniel


2 Answers

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.)

like image 69
Šime Vidas Avatar answered Nov 15 '22 16:11

Šime Vidas


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

like image 24
user12345 Avatar answered Nov 15 '22 16:11

user12345