CSS & Alternating Row Colors
I hoped that CSS was capable of alternating row colors in successive table rows but it seems not to be the case. The standard solution is to do a if (rownumber mod 2) server-side to alternate visual stylings. For a recent project, this wasn't an option, so I wrote a small script function alternateRowColors.GetElementsByTagName is a neat DOM method, working from the document root or from a subnode. For instance, you can run a getByTagName on a table to select the rows within it. In this case, running a general get all TRs wouldn't work, as we only want to do the visual markup on some of the page tables. The script uses a className setting to decide which tables to process.
There is a solution for this in CSS3:
tr:nth-child(odd)But we're not quite there yet -- Hixie recently offered some updates on CSS2.1 finalization.
|||
Posted at NaN:NaN, Published in: Code UI