HTML 表格列右对齐

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3665512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:25:54  来源:igfitidea点击:

HTML table column align right

htmlcsshtml-table

提问by Graslandpinguin

I have a table with 3 columns. I want that the third column is aligned to the right of the upper element and the other 2 columns to the left, like this:

我有一个 3 列的表。我希望第三列与上部元素的右侧对齐,其他 2 列在左侧对齐,如下所示:

(left column) (middle column)                                      (right column)

Is there a way to do this via CSS or something?

有没有办法通过 CSS 或其他方式做到这一点?

回答by Vinay B R

Use width:100%on the table and the middle column.

width:100%在桌子和中间的柱子上。

回答by pleasedontbelong

there are a few ways to do what you want. The most basic is to change the alignment directly in the tag

有几种方法可以做你想做的事。最基础的就是直接在标签中改变对齐方式

<td align='left'>data1</td><td align='right'>data1</td><td align='left'>data1</td>
<td align='left'>data2</td><td align='right'>data2</td><td align='left'>data2</td>
....

if you need to change something else (css style) you could create a class like .firstColumnand .secondColumnon each <td>

如果您需要更改其他的东西(CSS样式),你可以创建一个类像.firstColumn.secondColumn<td>

i tried to change directly the column but that doesn't work (HTML table colgroup element not working?

我试图直接更改列,但这不起作用(HTML 表 colgroup 元素不起作用?

回答by user2569050

<td style="text-align:right;">data1</td>

<td style="text-align:right;">data1</td>