HTML 在顶部对齐表格行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2659508/
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
HTML align table rows on top
提问by arik
I have an HTML table. It looks as follows:
我有一个 HTML 表格。它看起来如下:
<table>
<tr>
<td>Content one</td>
<td rowspan="2"> Very long content right</td>
</tr>
<tr>
<td>Content two</td>
</tr>
</table>
As you see, I have some very long content on the right side of the table, actually, it is so long that it does not fit into what height is given by the table rows, and so the table gets higher, and by doing that, the contents one and two are no longer at the top of the table, but distribute themselves along the whole height. How can I stop them from doing this?
正如你所看到的,我在表格的右侧有一些很长的内容,实际上,它太长以至于它不适合表格行给出的高度,所以表格变得更高,通过这样做,内容一和二不再在表的顶部,而是沿整个高度分布。我怎样才能阻止他们这样做?
EDIT:What I need is not the content to be aligned at the top, but the actual rows themselves.
编辑:我需要的不是要在顶部对齐的内容,而是实际的行本身。
采纳答案by lemzwerg
Interestingly, noone gave the correct answer yet, so I'm jumping in to close this question in a satisfactory way.
有趣的是,还没有人给出正确的答案,所以我想以一种令人满意的方式结束这个问题。
What you really need is the valign='baseline'
CSS property to align the first text lines of the <td>
elements.
您真正需要的是valign='baseline'
CSS 属性来对齐<td>
元素的第一行文本。
td {
vertical-align: baseline;
}
回答by user1123382
if you want to TD to be aligned at the top you need to set the vertical-align of the TR in the CSS not the TD
如果你想让 TD 在顶部对齐,你需要在 CSS 中设置 TR 的垂直对齐而不是 TD
回答by robr
<td valign='top' >
回答by Karthik
May be you use the div for internal scroll option without disturbing the page height.
可能您在不影响页面高度的情况下使用 div 进行内部滚动选项。