Alternate table rows using css

I have this code to alternate table rows in CSS, but it does not work. Any ideas?

<style type="text/css">
body {
  font: normal medium/1.4 sans-serif;
}
table {
  border-collapse: collapse;
  width: 100%;

}
th, td {
  padding: 0.25rem;
  text-align: left;
  border: 1px solid #ccc;
}
tr:nth-child(odd)            { background-color:#eee; }
tr:nth-child(even)            { background-color:#fff; }
</style>
</head>

<body>

<table width="100%" border="1" cellspacing="5" cellpadding="5">
  <tr>
    <td>fdsafds</td>
    <td>fdsa</td>
  </tr>
  <tr>
    <td>afsd</td>
    <td>fda</td>
  </tr>
  <tr>
    <td>dasf</td>
    <td>fdas</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>fdas</td>
  </tr>


</table>
BHUCAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
try
tbody tr:nth-child(odd)            { background-color:#eee; }
tbody tr:nth-child(even)            { background-color:#fff; }

Open in new window


see another example with assigning a class here:

http://www.textfixer.com/tutorials/css-table-alternating-rows.php

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BHUCAuthor Commented:
That doesn't work either. I have actually copied and pasted the code in the sample you gave me and it doesn't work either.
Kyle AbrahamsSenior .Net DeveloperCommented:
is your browser CSS3 compatible?  (EG: IE11 or better, Chrome, firefox?)

Can you post a link to the page?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

BHUCAuthor Commented:
That's it....  thanks...  worked in chrome - not in IE
BHUCAuthor Commented:
Anything for something not compatible with CSS3?
Kyle AbrahamsSenior .Net DeveloperCommented:
Jquery or javascript.  Found the below online:

function altrows(classname,firstcolor,secondcolor)
{
   var tableElements = document.getElementsByClassName(classname) ;
   for(var j= 0; j < tableElements.length; j++)
   {
      var table = tableElements[j] ;

      var rows = table.getElementsByTagName("tr") ;
      for(var i = 0; i < rows.length; i++)
      {
        rows[i].bgColor = (i%2==0) ? firstcolor : secondcolor ;
      }
   }
}

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.