15 - 09 - 2003


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

Navigate:

<< Tab Navigation for the Web
DHTML Spotting: UseText>>


Surf*Mind*Web

Deepen
Browse



search collections


Best of the Blog

08/00 Customization Drawbacks
12/00 Fish-eye Craigslist (IE)
07/01 Smart webserver log analysis
03/03 Junkie: Adaptive Freshness
04/03 Cascading Fish-eye Menus
05/03 Browser Maps (dhtml)
01/03 GOMS in Bugzilla.mozilla?
10/03 CSS Link Markers
01/04 Blog Mountain
03/04 Personal Web Information Manager
04/04 Mousing Behavior in Windows
06/04 DHTML Multi-Select Widget

More Andyed Weblogs:

Cold Fusion Blog: experiences as an instructor & developer.

Clemson Human Factors: master's program notes.

Andyed's Mozilla Projects
aka "chromeantics"

Mozwho: personal adaptive homepage and bookmark/history API for Mozilla.

Optimoz Gestures Back and Forward with a wrist flick or mouse rocker

GoogleBar for Moz