Log in

View Full Version : Help with column justification PLEASE!



mogomuta
09-30-2008, 02:15 AM
I have a problem with table columns. Columns 1 & 2 are left
justified, and column 3 is right justified. Currently, the code is:

<colgroup style="text-align: left"></colgroup>
<colgroup style="text-align: left"></colgroup>
<colgroup style="text-align: right"></colgroup>

<tr>
<td>this column is left</td>
<td>this column is left</td>
<td>this column is right</td>
</tr>

It works in IE, but Firefox does not like that, and all columns show
as left justified.

I know I can use <td style="text-align: right"> but the table is
over 500 rows, and I don't want to make 500 changes.

Can I right-justify just the third column in my .css file? If so,
how?

TheJoshMan
09-30-2008, 09:40 PM
well, depending on what the REST of your code looks like... you can use nested styling if you don't want to go through and change each individual <td> to add a class to it or use inline styling.

It would look something like this..



<style type="text/css">
tr td td td {
text-align:right;
}

Medyman
09-30-2008, 11:17 PM
@mogomuta...
The trouble here is that text-align for use on <colgroups> or <col> isn't part of any W3C standard. So, the standard-compliant browsers have neglected to implement in. IE, because it can't do EVERYTHING wrong, is kind of ahead of the curve in adding it.

But, since all of the modern browsers (to my knowledge, anyway)in their most recent releases now have support for :first-child and sibling selectors, you can indeed do it via CSS.

Keep the inline styles that you have already for IE's sake. For everything else, use the following:

<style type="text/css">
td:first-child + td + td {
text-align:right;
}
</style>

@Josh...
That would work if there were 2 nested tables within each cell. That's not the case here.