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

jco*_*ahd 11 html css forms internet-explorer

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

我有:

input#search {
    float:left;
    font-size:11px;
    height:20px;
    margin:0;
    padding-left:4px;
    width:100px;
}
Run Code Online (Sandbox Code Playgroud)

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

Pau*_*eno 43

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

input { border: 0; font-size: 0.8em; height: 32px; line-height: 32px;}
Run Code Online (Sandbox Code Playgroud)

gl Paulo Bueno


小智 7

只是定义line-heightheight与相同值的文本框中.它会得到照顾


Sar*_*raz 1

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

<!--[if IE]>
input#search{
  padding-top:3px;    /* adjust value */
}
<![endif]-->
Run Code Online (Sandbox Code Playgroud)