Alex Rivera | Logout

tr:nth-child(even) help. how to apply to one class?

Asked 2009-10-15T01:07:39.570
10

I'm not very good with CSS and I need some help.

I have a table where i want every other row to be gray and the alternating rows to be white. but i only want it to happen on one particular table.

I added some code to my CSS:

tr:nth-child(even) {  
background: #CCC;  
}  

tr:nth-child(odd) {  
background: #FFF;  
}  

but the problem is that its affecting every table on my site. I haven't found any examples where it applies only to a certain class. Is that possible? I want it to apply only to:

table.dashboardtable  
Edit
Report

1 Answer

3

Hope this makes sense of it.

<!DOCTYPE html>

<html>
  <head>
    <style type="text/css">
      #customers tr:nth-child(even){
        background-color:white;
      }
      #customers tr:nth-child(odd){
        background-color:Lavender;
      }
    </style>
  </head>

  <body>
    <p>In your markup define your table:</p>
      <table id="customers"></table>
  </body>
</html>
answered 2012-05-16T22:22:14.553

Your Answer