Cheap Shared Hosting

Friday, July 25, 2008

CSS table tip - right-aligned column

Just a quick tip, it's been a long time! I've been sick and busy, which is definitely not a good combination...

Making the first column right-aligned
Suppose you need to make the contents of the first column right-aligned. An easy way to do this (assuming you have a special class/id for the table) is to use the first-child selector:


table.mytable tr td:first-child {
text-align: right;
}

2 comments:

Echilon said...

I'm pretty sure IE6 doesn't support this, but it's still useful. (Who uses IE6 ;)

The Author said...

Well, I think it's still a pretty big percentage unfortunately - probably bigger than safari for example. Thankfully the site I used this one didn't have to support IE6, but it'd definitely be worth checking before relying on it.