[drupal-devel] [bug] Zebra stripe table CSS class names are badly chosen

Thox drupal-devel at drupal.org
Thu Jun 16 08:11:03 UTC 2005

Issue status update for http://drupal.org/node/25067

 Project:      Drupal
 Version:      4.6.0
 Component:    base system
 Category:     bug reports
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  Thox
 Updated by:   Thox
 Status:       patch

factoryjoe, I'd agree with your reason for using "alt" only if it was
not simply a bad substitute of the same concept. Using your same
arguement, after rearranging rows, you would have possibly two rows at
the top with the "alt" class, followed by three rows with nothing.

Regardless of the name used, if you're going to move rows with
javascript then you must relabel the class names.

The benefit of using two classnames is quickly seen if you look at the
stylesheets. drupal.css and others all style tables rows based on
td.light and td.dark. If you styled "td" then you would affect any
structural tables used in the theme.


Previous comments:

June 15, 2005 - 14:58 : Thox

Attachment: http://drupal.org/files/issues/zebra-classnames.patch (1.41 KB)

The CSS class names chosen for table rows are badly chosen: "light" and
"dark". Since CSS could be used to make the "dark" rows light and the
"light" rows dark, the names are wrong. The attached patch changes
"light" and "dark" to "odd" and "even".

In the future, all class names should describe /why/ an element is
styled differently, not /how/ it is to be styled. e.g. "Red" is a bad
class name, "important" is far better.


June 15, 2005 - 16:37 : Bèr Kessels

themes/bluemarine/style.css:13:tr.dark td, tr.light td {
themes/pushbutton/style.css:27:tr.dark td, tr.light td {
themes/pushbutton/style.css:512:#tracker tr.light, #tracker tr.dark {
themes/pushbutton/style.css:542:#forum tr.dark {

are core styles still using dark and light. jsut a quick grep.
but other than that a +1 for these better named classes.


June 15, 2005 - 19:37 : drumm

I have a 80% finished patch on my Drupal checkout which:

- Adds <thead> and <tbody>
- Allows use of <th> in the table body.
- Unifies the classing for the block admin and permissions tables. (I
might codify this in a themeable function.)
- Removes the light class and changes the dark class to alt.
- Adds a class to the <table> tag made by theme_table() to avoid
styling conflicts with layout tables found in some themes.

Many of these changes were suggested by Chris [1].

I will be able to finish and post this patch in some number of weeks.
Please don't worry aobut submitting conflicting patches, I can deal
with it. Although we might want to decide upon odd/even and alt/[none]
classing now.
[1] http://factoryjoe.com/blog/


June 15, 2005 - 23:12 : Steven

I'd prefer "odd"/"even" than ""/"alt". It is more descriptive.


June 16, 2005 - 04:33 : TDobes

I agree... "odd"/"even" seems preferable.


June 16, 2005 - 05:53 : factoryjoe

I disagree with "odd" and "even" just as much as "dark" and "light".
Why? Well, with Javascript you can rearrange table rows. "Odd" and
"even" refer to relative positions within a fixed numerical order. I
would presume that when you rearrange rows, the classes are moved too
(for example, in the watchdog, the "error" class might show up on a row
and should therefore be moved with that row when sorting). So by using
the "alt method", you not only cut down on code by using /just/ the
"alt" class on every other <tr> tag, but you also get simpler markup.
Your intention, after all, is to denote alternating rows, not whether
the rows are "odd" or "even".

I also don't see any benefit in styling two different row classes; just
treat unclassed rows as the default and use the .alt class  for visual
distinction. It's that simple.

More information about the drupal-devel mailing list