Forum Moderators: not2easy

Message Too Old, No Replies

styling a table column

one column out of 5

         

benihana

11:59 am on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a table with five col's and hundreds of rows.

One column needs to be text-aligned right.

Im wondering if there is a more elegant solution than adding a class to each td in that col.

Ive tried

tr+td+td+td {
text-align;right;
}

but obviously browser support doesnt cut it.

What id reall ylike is something that does:

td:third-child {
text-align:right;
}

and is cross browser. :(

:(

Any thoughts?

Cheers

Ben

Ingolemo

1:55 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



You can style columns using the <col> element.

CSS:


col#age {background-color:#f00;}

HTML:


<table>
<col>
<col id="age">
<thead><tr><th>Name</th><th>Age</th></tr></thead>
<tbody>
<tr><td>Tom</td><td>20</td></tr>
<tr><td>Dick</td><td>30</td></tr>
<tr><td>Harry</td><td>40</td></tr>
</tbody>
</table>

jalarie

2:03 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



How about using the <colgroup> and <col> tags?

benihana

3:11 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok. thanks guys.

Have to say, ive never used the col tags, ill give them a try.

cheers!