views:

938

answers:

3

My Table structure is like follows:

<table>
 <thead>
   <tr class="navigation">
   </tr>
 </thead>
 <thead>
   <tr class="headers">
   </tr>
 </thead>
 <tbody>
  <tr class="even">
    <td><a href="#"/></td>
  </tr>
  <tr class="odd">
  </tr>
  </tr>
 </tbody>
</table>

I have defined following CSS ,how can apply "navigation","header","even","odd" classes in my CSS? How to define them relate to 'table' class like 'table.even','table.odd' ? thanks

table{
    font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
    font-size: 10px;
    #margin: 45px;
    width:100%;
    text-align: left;
    border-collapse: collapse;  
}
+1  A: 

Applying a class to any element allows you to do the following:

element.className { rules }

So with your TR, you could do the following:

tr.navigation { font-weight:bold }

So creating zebra-stripes on your odds and event rows can be done like this:

tr.odd  { background-color:#FFF; }
tr.even { background-color:#CCC; }
Jonathan Sampson
+1  A: 

you would use

table thead tr.navigation {}
table thead tr.headers {}
table tbody tr.even {}
table tbody tr.odd {}
devians
@devians, per my answer this is completely inefficient. You're better off to use .navigation for your table rows and if you have to define different styles on a different element, use a different class name.
jeerose
+3  A: 

Only reference the parent element's class or the parent element itself if you have to use the class name for more than one type of element. For example, this:

.navigation { font-weight:bold }

...instead of this:

tr.navigation { font-weight:bold }

It will cut down on load time when the browser renders the page.

Reference: Optimize browser rendering [Google Code]

jeerose
For the sake of future maintainability, atleast classing the table and using a slight bit of inheritance is a good idea unless you are 100% this is a global class.
devians