CSS 表格 td 垂直对齐文本顶部

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

CSS table td vertical-align text-top

cssvertical-alignment

提问by user5332

I have problem with vertical-align to text-top on tables

我在垂直对齐表格上的文本顶部时遇到问题

I have globally set at table tdto vertical-align: middle.

我已经在表中全局设置tdvertical-align: middle.

Now I need to change only onetdto vertical-align: text-top

现在我只需要将一个更改tdvertical-align: text-top

The problem is, that all variant that I tested set vertical-align:text-topare shown as toponly

问题是,我测试集的所有变体vertical-align:text-top都仅显示为顶部

("xxxx" in image is not at same line as "yyyy")

(图像中的“xxxx”与“yyyy”不在同一行)

Only one variant is working as text-top, and that is change globally style of all td(I don't want this, I need to change only onetd)

只有一个变体在工作text-top,那就是改变所有的全局样式td(我不想要这个,我需要改变一个td

SEE IMAGES

查看图片

Setting as local style is shown as toplocal style http://aukro.svecpetr.com/style.png

设置为本地样式显示为顶级本地样式 http://aukro.svecpetr.com/style.png

Setting as class is shown as toplocal style http://aukro.svecpetr.com/class.png

设置为类显示为顶级本地样式 http://aukro.svecpetr.com/class.png

Changing global tdhas the right effect of text-toplocal style http://aukro.svecpetr.com/global-style.png

更改全局td具有文本顶部本地样式的正确效果http://aukro.svecpetr.com/global-style.png

EXAMPLEyou could find at https://zbozimat.cz/test.php

示例您可以在https://zbozimat.cz/test.php找到

Could somebody help me?

有人可以帮助我吗?

回答by hafid2com

Add this for div:

为 div 添加这个:

display: inline-block;
vertical-align: top;

And this for input:

这是输入:

display: inline-block;
vertical-align: top;