Html 我想将 <td> 中的文本与顶部对齐

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5671687/
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 08:00:50  来源:igfitidea点击:

I want to align the text in a <td> to the top

htmlcss

提问by Buffon

I have the following code

我有以下代码

<table style="height: 275px; width: 188px">
    <tr>
        <td style="width: 259px;">
            main page
        </td>
    </tr>
</table>

The main page appears in the center of the cell I want it to appear at the top.

主页出现在我希望它出现在顶部的单元格的中心。

回答by thirtydot

https://developer.mozilla.org/en/CSS/vertical-align

https://developer.mozilla.org/en/CSS/vertical-align

<table style="height: 275px; width: 188px">
    <tr>
        <td style="width: 259px; vertical-align:top">
            main page
        </td>
    </tr>
</table>

?

?

回答by Vik David

Add a vertical-alignproperty to the TD, like this:

vertical-align向 TD添加一个属性,如下所示:

<td style="width: 259px; vertical-align: top;">
main page
</td>

回答by Jay

Use <td valign="top" style="width: 259px">instead...

使用<td valign="top" style="width: 259px">,而不是...

回答by Faraz Ahmad Ramish

you can use valign="top"on the td tag it is working perfectly for me.

你可以valign="top"在 td 标签上使用它对我来说非常完美。

回答by Basheer AL-MOMANI

I was facing such a problem, look at the picture below

我正面临这样的问题,请看下图

enter image description here

在此处输入图片说明

and here is its HTML

这是它的 HTML

<tr class="li1">
    <td valign="top">1.</td>
    <td colspan="5" valign="top">
        <p>How to build e-book learning environment</p>
    </td>
</tr>

so I fix it by changing valign Attributein both tdtags to baseline

所以我通过将两个标签中的valign 属性更改tdbaseline

and it worked

它起作用了

here is the result enter image description here

这是结果 在此处输入图片说明

hope this help you

希望这对你有帮助