Html 垂直对齐:文本顶部;在 HTML5 中的表格单元格 (td) 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12631954/
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
vertical-align:text-top; not working in table cell (td) in HTML5
提问by 4michaelcoleman
Not sure why but for the life of me I cannot get my text to align on the top of a table cell (td) when the cell before it is wrapping text.
不知道为什么,但对于我的生活,当单元格在换行文本之前,我无法让我的文本在表格单元格 (td) 的顶部对齐。
If I write it out in the HTML it works, but unable to get the same effect in my CSS.
如果我将它写在 HTML 中它可以工作,但无法在我的 CSS 中获得相同的效果。
Works with HTML:
适用于 HTML:
<td style="vertical-align:text-top;">Some Text</td>
Doesn't with CSS:
不使用 CSS:
table td { vertical-align: text-top; }
And I have tried every combination you can think of within my CSS
我已经尝试了在我的 CSS 中你能想到的所有组合
回答by Ryan Wheale
Make sure you are not setting "display: block" on the TD elements, as vertical align doesn't work on block elements. Also, text-top is not the best, and has some cross browser issues. Use "top" instead. Try adding this in your stylesheet:
确保您没有在 TD 元素上设置“显示:块”,因为垂直对齐不适用于块元素。此外, text-top 不是最好的,并且存在一些跨浏览器问题。改用“顶部”。尝试将其添加到您的样式表中:
table td {
display: table-cell;
vertical-align: top;
}