Html 在 Internet Explorer 中的文本输入中垂直居中文本

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

Vertically center text in text input in Internet Explorer

htmlcssformsinternet-explorer

提问by jcoahd

I am having trouble vertical aligning text in an input field in Internet Explorer.

我在 Internet Explorer 的输入字段中垂直对齐文本时遇到问题。

I have:

我有:

input#search {
    float:left;
    font-size:11px;
    height:20px;
    margin:0;
    padding-left:4px;
    width:100px;
}

In Firefox and Chrome, it seems to be automatically vertical aligned, however in Internet Explorer it is not.

在 Firefox 和 Chrome 中,它似乎是自动垂直对齐的,但在 Internet Explorer 中却不是。

回答by Paulo Bueno

Just set the height and line-height for the input object and it works fine (ie 7+).

只需为输入对象设置高度和行高,它就可以正常工作(即 7+)。

input { border: 0; font-size: 0.8em; height: 32px; line-height: 32px;}

gl Paulo Bueno

保罗·布埃诺

回答by Chinni

Just define line-heightand heightfor a text box with same value. It will be taken care

只需为具有相同值的文本框定义line-heightheight。会被照顾

回答by Sarfraz

You can use IE conditional comment like this:

您可以像这样使用 IE 条件注释:

<!--[if IE]>
input#search{
  padding-top:3px;    /* adjust value */
}
<![endif]-->

回答by Marcel

Setting line-height:1might mitigate the vertical alignment and a bit of padding:.15emshould add some breathing space to the fields too.

设置line-height:1可能会减轻垂直对齐,并且也padding:.15em应该为字段增加一些呼吸空间。

回答by gamliela

Check the parent div. If it's empty you need to add content (&nbps;) so explorer will calc the height correctly.

检查父div。如果它是空的,您需要添加内容 (&nbps;),以便资源管理器正确计算高度。