I have an HTML table with a large number of rows, and I need to right align one column.
I know the following ways,
<tr><td>..</td><td>..</td><td align='right'>10.00</td><tr>
and
<tr><td>..</td><td>..</td><td class='right-align-class'>10.00</td><tr>
In both the methods, I have to repeat the align or class parameter on every <tr> tag. (If there are 1000 rows, I have to put align=’right’ or class=’right-align-class’ 1000 times.)
Is there an efficient way to do this? *Is there a direct way to say, align the third column in all rows to the right?
Updated (after 10+ years!): Yes! It’s possible to do this more efficiently now, with widespread practical browser support, using the
nth-childselector.HTML:
CSS:
https://jsfiddle.net/mv83qszL/
Previously, it was not possible to do this, because browser support used to be inconsistent and hit-or-miss, especially with regard to newer CSS features. This made it impossible to use more elegant, efficient solutions — and required lots of repetitive markup and class definitions in order to get consistent results across the audience’s browser space.
See the edit history for the previous version of this answer.