如何将文本与 ?

时间:2022-09-07 10:45:35

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. Latest Chrome, FF5

注。最新的Chrome,FF5

3 个解决方案

#1


5  

Apparently only IE and Opera allow align.

显然只有IE和Opera允许对齐。

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).

更新后,col只能有边框、背景、宽度和可见性。与css继承有关。http://ln.hixie.ch/?start= 1070385285and count=1(注意,我只浏览了这篇文章,但它看起来像是一个不错的读物)。

#2


1  

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.

15年来,人们一直在excel中对文本进行右对齐,但最新最好的HTML 5却无法处理。

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 * means it it too difficult to align text in HTML

这更像是一场咆哮,但答案是让标准委员会的一些人知道他们在做什么。我肯定会得到我的答案,但这个问题必须在*上被提出来,这就意味着要在HTML中对齐文本太难了

#3


-1  

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

您可以将类应用到col元素,然后按您希望的方式进行样式设置。

<col class="something" />

And

col.something
{
    text-align: right;
}

#1


5  

Apparently only IE and Opera allow align.

显然只有IE和Opera允许对齐。

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).

更新后,col只能有边框、背景、宽度和可见性。与css继承有关。http://ln.hixie.ch/?start= 1070385285and count=1(注意,我只浏览了这篇文章,但它看起来像是一个不错的读物)。

#2


1  

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.

15年来,人们一直在excel中对文本进行右对齐,但最新最好的HTML 5却无法处理。

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 * means it it too difficult to align text in HTML

这更像是一场咆哮,但答案是让标准委员会的一些人知道他们在做什么。我肯定会得到我的答案,但这个问题必须在*上被提出来,这就意味着要在HTML中对齐文本太难了

#3


-1  

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

您可以将类应用到col元素,然后按您希望的方式进行样式设置。

<col class="something" />

And

col.something
{
    text-align: right;
}