Table column alignment testing

The purpose is to find the best way to align all cells in a column to the right. In the test tables, the first column should not be affected but the second column should be right-aligned.

Using align="right" 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 align="right">

Hello world 42
Foo bar 1 000 000
Zap 123

Using style="text-align:right" 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="text-align:right">

It seems that according to clause 17.3 Column selectors of the CSS2 specification, this actually should not work, since text-align is not one of the properties that apply to columns.

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 { text-align: right }. 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 alignment 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 second column right-aligned.

On Windows 98, Netscape 4.51 shows the tests that are not based on a col element with the second column right-aligned. The same applies to Mozilla 1.2.1 and Opera 6.03.

On Unix, Lynx version 2.8.4 shows the first two tests with the second column right-aligned.


Jukka "Yucca" Korpela