Table column background testing

The purpose is to find the best way to set a background for a column. In the test tables, the first column should not be affected but the second column should have yellow background.

Using bgcolor="#ffffcc" in all cells of the column

This is most probably the most certain way, but it's clumsy. And it's not Strict.

Hello world 42
Foo bar 1 000 000
Zap 123

Using <col bgcolor="#ffffcc">

Hello world 42
Foo bar 1 000 000
Zap 123

Using style="background-color:#ffffcc" in all cells of the column

This probably works on all CSS enabled browsers, but it's clumsy.

Hello world 42
Foo bar 1 000 000
Zap 123

Using <col style="background-color:#ffffcc">

It seems that according to clause 17.3 Column selectors of the CSS2 specification, this actually should not work, since "the background properties set the background for cells in the column, but only if both the cell and row have transparent backgrounds".

Hello world 42
Foo bar 1 000 000
Zap 123

Using <col> with a class and separate style sheet

The markup has <col class="num"> and the style sheet contains .num { background: #ffc }. This would let us use a separate style sheet instead of an embedded one. (In this test, the separate style sheet is in a style element, but naturally it could, and normally should, be in a separate file.)

Clause Inheritance of background specifications (!) in the HTML 4.01 specification seems to imply that the style attribute is to be inherited. It's really an en passant statement: "The order of precedence (from highest to lowest) for the attribute valign (as well as the other inherited attributes lang, dir, and style) is - -".

Hello world 42
Foo bar 1 000 000
Zap 123

Using a class attribute in all cells of the column

This uses <td class="num"> for all cells of the column, with the style sheet as above.

This probably works on all CSS enabled browsers, complies with Strict rules and complies with the principle of using a separate (not embedded) style sheet, but it's clumsy.

Hello world 42
Foo bar 1 000 000
Zap 123

Some results

On Windows 98, Internet Explorer 6.0 shows all the tests with the desired background color.

On Windows 98, Netscape 4.51 shows the tests that are not based on a col element with the desired background color. The same applies to Mozilla 1.2.1 and Opera 6.03.


Jukka "Yucca" Korpela