Tuesday, March 16, 2010

Col, Colgroup and XHTML alignment

According to our great and wonderful masters we shouldn't use tables to line-up our web-page content; fine I accept that it makes repositioning and re-styling much easier. However when it comes to presenting actual data such tables are still 'allowed'

So I'm setting out some data and I need some of the columns to be a different background colour and I need to set the widths rather than let it sort itself out. A perfect job for the colgroup and col element. I can start the table with this section and specify attributes for each column without having to shove classes into every third td. All is great until I try to centre the third column's text. It doesn't work. In fact it doesn't work in Firefox, it doesn't work in Opera, it doesn't work in Chrome; amusingly the only one it does work in is IE7.

Yup of the four big engines (the rendering part of the browsers) only the much maligned IE7 understands text-alignment of columns when trying to use XHTML. Has the world has gone mad?

2 comments:

Orphi said...

Yes.

But regarding your specific issue… ;-) I wasn't entirely sure whether this is still in the XHTML standards, but it appears that it is. It's just not especially widely supported.

As to why, I can only guess because everybody has decided that tables are evil, and forgotten that they are in fact useful for… well… tables. You know, when you have an actual table of data!

FlipC said...

Oh yeah I checked to make sure someone hadn't done something dumb like remove those attributes all together; but nope still there, still official, non-deprecated in XHTML, fine and dandy, attributes.

It just doesn't work in anything except IE.

From FireFox it can seen to be an 11 year-old problem according to w3schools Opera is supposed to handle it; except not in my copy of v10.5 it don't.