How to right align text in table cell with <col/>
I want the second column to be right-aligned and I don't want to apply styles to <td>
element. From what I've 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>
with no luck as well. Any ideas?
p.s. 开发者_C百科Latest Chrome, FF5
Apparently only IE and Opera allow align
.
Update, col
should only have border
, background
, width
& visibility
. Has to do with css inheritance. http://ln.hixie.ch/?start=1070385285&count=1 (note, I only skimmed this article but it seemed like a decent read).
How exactly do people who set the standards operate? The obvious thing to do would be have the new way working before removing something from the standard. I am disappointed that this is not easy.
People have been right-aligning text in excel for 15 years yet the latest & greatest HTML 5 can't handle it.
This is more of a rant but the answer is get some people on the standards committee who know what they are doing. I'm sure to be slated for my answer but the fact that the question had to be asked on StackOverflow means it it too difficult to align text in HTML
You can apply a class to the col
element, and then style however you want.
<col class="something" />
And
col.something
{
text-align: right;
}
精彩评论