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
Vertically center text in text input in Internet 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-height
and height
for a text box with same value. It will be taken care
只需为具有相同值的文本框定义line-height
和height
。会被照顾
回答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:1
might mitigate the vertical alignment and a bit of padding:.15em
should 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;),以便资源管理器正确计算高度。