Html 如何在跨越多行的 <td> 单元格中顶部、左对齐文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6389085/
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 09:09:38 来源:igfitidea点击:
How to top, left justify text in a <td> cell that spans multiple rows
提问by Kevin Le - Khnle
I have the following html code:
我有以下 html 代码:
<table border="1">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>0</td>
</tr>
<tr>
<td>February</td>
<td rowspan="2">Save a lot</td>
</tr>
<tr>
<td>March</td>
</tr>
</table>
Using CSS styling or another method, can I make the text "Save a lot" top, left justified?
使用 CSS 样式或其他方法,我可以将文本“Save a lot”置于顶部,左对齐吗?
回答by Tomalak
回答by Blindy
<td rowspan="2" style="text-align:left;vertical-align:top;padding:0">Save a lot</td>
That should do it.
那应该这样做。
回答by Iyes boy
try this
尝试这个
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table style="width:50%;">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr style="height:100px">
<td valign="top">January</td>
<td valign="bottom">0</td>
</tr>
</table>
<p><b>Note:</b> The valign attribute is not supported in HTML5. Use CSS instead.</p>
</body>
</html>
use valign="top" for td style
使用 valign="top" 作为 td 样式