如何在跨越多行的单元格中向上,左对齐文本[英]How to top, left justify text in a cell that spans multiple rows 本文翻译自  Kevin Le - Khnle  查看原文  2011-06-17  105065    css/

时间:2022-02-12 20:34:46

I have the following html code:

我有以下HTML代码:

<table border="1">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</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样式或其他方法,我可以使文本“保存很多”顶部,左对齐吗?

3 个解决方案

#1


65  

td[rowspan] {
  vertical-align: top;
  text-align: left;
}

See: CSS attribute selectors.

请参阅:CSS属性选择器。

#2


9  

 <td rowspan="2" style="text-align:left;vertical-align:top;padding:0">Save a lot</td>

That should do it.

应该这样做。

#3


1  

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">$100</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

对于td样式,请使用valign =“top”

#1


65  

td[rowspan] {
  vertical-align: top;
  text-align: left;
}

See: CSS attribute selectors.

请参阅:CSS属性选择器。

#2


9  

 <td rowspan="2" style="text-align:left;vertical-align:top;padding:0">Save a lot</td>

That should do it.

应该这样做。

#3


1  

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">$100</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

对于td样式,请使用valign =“top”