Forum Moderators: not2easy

Message Too Old, No Replies

Question about using CSS to format alternate table cells

         

Durnovaria

5:32 am on Apr 1, 2007 (gmt 0)

10+ Year Member



Hello

Just a couple of quick questions here! Are there any CSS rules that I could use to allow me to format specific elements of a table, without actually altering the HTML of every cell I want to change?

For example, I have a 3-column, 50-row table.

Could I attach a rule in the main table tag to allow me to have no cell padding in column 2, but still have cell padding on columns 1 and 3?

Could I attach a rule in the main table tag to change the colour of every other row in this table, so I get odd numbered rows with a white background and even numbered rows with a coloured background?

Thanks very much

:-)

JAB Creations

6:04 am on Apr 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll want to use colgroups to effect columns as a whole without editing each and every cell's class/id.

<table style="font-size: 12px; width: 100%;" summary="Your table summary here.">
<colgroup style="width: 50%;"></colgroup>
<colgroup style="width: 50%;"></colgroup>
<tr><td></td></tr>
<tr><td></td></tr>
</table>

As for alternating colors of alternating rows that is only supported in CSS3 and so where you see it effectively implemented online right now (2007) is due to serverside manipulation.

Here is the CSS3 Spec [w3.org].

- John

The CSS3 code

Dabrowski

12:15 pm on Apr 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use a bit of JS to alternate colours?

I have tables like this but generated from a server script so I do the colours there.