[Project_owners] Table row formatting with CSS

Gerald Vogt vogt at spamcop.net
Thu May 4 20:45:53 EDT 2006

In an attempt to cleanup my generated HTML from embedded formatting I 
was wondering if it is possible to format HTML elements in an 
alternating way, for instance format rows in a table with two or more 
colors alternately.

At the moment the generated HTML looks something like:

<tr class="c1">contents here</tr>
<tr class="c2">contents here</tr>
<tr class="c1">contents here</tr>
more rows go here

But obviously, if I wanted to switch this to a three color alternation 
(c1, c2, c3) I would have to modify my source code to generate different 
code. I could assign each row an individual class but that way I would 
have to know the maximum number of rows which I do not know. So I 
thought there should be a way to use the same class for all rows (e.g. 
"c") and the definition for that class would do the alternation. But 
after browsing through the CSS2 spec I have the impression that this is 
not possible.

Is it possible to do this kind of alternations just with CSS, i.e. 
without the need to put it into the generated HTML code?

Thx, Gerald

More information about the Project_owners mailing list