使用CSS格式化文本

huangapple go评论94阅读模式
英文:

Formatting text in the with CSS

问题

我使用HTML创建了一个表格,但我希望每行的文本位于每个单元格的顶部,而不是居中。如果您有解决方案,请帮忙。

我希望文本位于每个单元格的顶部,但实际上它只在中间。

英文:

I created a table with HTML, but I want my text in each row to be at the top of each cell and not at the center. Please help if you have a solution

I expected the text to be at top: 0 of each cell but it's just at the center

答案1

得分: 1

vertical-align: top; 可以为您完成这项操作。

检查下面的示例:

  1. table {
  2. border-collapse: collapse;
  3. }
  4. table tr td {
  5. height: 100px;
  6. border: 1px solid #ddd;
  7. vertical-align: top;
  8. padding: 5px;
  9. }
  1. <table>
  2. <tbody>
  3. <tr>
  4. <td>1</td>
  5. <td>2</td>
  6. <td>3</td>
  7. <td>4</td>
  8. </tr>
  9. </tbody>
  10. </table>
英文:

vertical-align: top; does the magic for you.

Check the below example

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

  1. table {
  2. border-collapse: collapse;
  3. }
  4. table tr td {
  5. height: 100px;
  6. border: 1px solid #ddd;
  7. vertical-align: top;
  8. padding: 5px;
  9. }

<!-- language: lang-html -->

  1. &lt;table&gt;
  2. &lt;tbody&gt;
  3. &lt;tr&gt;
  4. &lt;td&gt;1&lt;/td&gt;
  5. &lt;td&gt;2&lt;/td&gt;
  6. &lt;td&gt;3&lt;/td&gt;
  7. &lt;td&gt;4&lt;/td&gt;
  8. &lt;/tr&gt;
  9. &lt;/tbody&gt;
  10. &lt;/table&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月15日 18:27:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76481582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定