Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS Best Practices for Tables 1

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,
(incomming newbie question...)

I have a .css file that has entries for a how I would like "most" of my tables to be presented with entries as outlined below. I want to have a different set of table styles for how I present reports using a table.

What is the easiest to manage way to use CSS with different table styles?
table {
...
}
th
...
}
tr
...
}
td
...
}



Thanks,

Michael42
 
Create psuedo classes for your table and then use the "class=" attribute.

There's always a better way. The fun is trying to find it!
 
Easiest way is to create another table class and make other elements dependent of that class:
Code:
<style type="text/css">
table { ... }
th { ... }
tr { ... }
td { ... }

table.reports { ... }
table.reports tr { ... }
table.reports th { ... }
table.reports td { ... }
</style>
<table>
 <tr>
  <th>Head</th>
 </tr>
 <tr>
  <td>This is a normal table</td>
 </tr>
</table>

<table class="reports">
 <tr>
  <th>Different head</th>
 </tr>
 <tr>
  <td>This is a reports table</td>
 </tr>
</table>
 
This looks to easy :)

Given your example, is <table class="reports"> sufficient or to all the tags in the html table (th,tr,td) need to have class="reports" too?

Thanks very much,

Michael42
 
That is sufficient. To elaborate on what the syntax is telling. Your part redefines the normal look for the elements table, tr, th and td. My added styles define a table that has a class called reports and every tr, th and td element within this table. Hope it is clear.
 
>>Hope it is clear.

Yes - thanks very much for elaborating. :)

I am starting to "get" CSS and seeing what a big impact it can have.

Take Care,

Michal42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top