I want the second column to be right-aligned, and I don't want to apply styles to theelemen...">

How to align text in a table cell using <col / ">

I want the second column to be right-aligned, and I don't want to apply styles to the <td> element. From what I read, <col> is the way to go, but it does not work for me:

 <table> <col style="width: 20em" /> <col align="right" style="text-align: right" /> <col /> <tbody> <tr> <td>123</td> <td>1</td> <td>2</td> </tr> <tr> <td>12345678</td> <td>189</td> <td>2</td> </tr> </tbody> </table> 

Tried <colgroup> and no luck. Any ideas?

ps Latest Chrome, FF5

+4
source share
3 answers

Apparently, only IE and Opera allow align .

The col update should only have border , background , width and visibility . Related to css inheritance. http://ln.hixie.ch/?start=1070385285&count=1 (mind you, I just looked through this article, but it looked like a decent read).

+5
source

How exactly do standard-setting people work? The obvious thing to do is use the new method before removing anything from the standard. I am disappointed that this is not easy.

People have the right to align text in excel for 15 years, but the latest and greatest HTML 5 can't handle it.

It is more like rant, but the answer is that some people on the standards committee know what they are doing. I'm sure I have to answer for this, but the fact that the question should have been asked in StackOverflow is too difficult to align text in HTML

+1
source

You can apply the class to the col element, and then the style you want.

 <col class="something" /> 

and

 col.something { text-align: right; } 
-1
source

All Articles