Setting table background colour

liunx

Guest
Hi,

I know that you can use tr { background: #30A2B6; }

to set the colour of a table row, but I need two different coloured rows, one for the table header and one for the rest of the table.

I was hoping I could use something like trtop { background: #30A2B6; }
and
trbottom { background: #586868; }

but I can't get it to work. Where am I going wrong ?There isn't anything "automatic". You can use classes:

<style type="text/css">
tr.top { background: #30A2B6; }
tr.bottom { background: #586868; }
</style>
...
<table>
<tbody>
<tr class="top">
...
</tr>
...
<tr class="bottom">
...
</tr>
</tbody>
</table>Star.

Many thanks! :cool:You can also break your table up into a THEAD and a TFOOT element separated by any number of TBODY elements. Sort of like DIVs. See <!-- m --><a class="postlink" href="http://www.w3.org/TR/html4/struct/tables.html#h-11.2.3">http://www.w3.org/TR/html4/struct/tables.html#h-11.2.3</a><!-- m -->.
 
Back
Top