Vertically center text in text input in Internet E

2020-05-26 16:32发布

I am having trouble vertical aligning text in an input field in 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.

5条回答
兄弟一词,经得起流年.
2楼-- · 2020-05-26 17:09

Just define line-height and height for a text box with same value. It will be taken care

查看更多
贪生不怕死
3楼-- · 2020-05-26 17:14

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

查看更多
4楼-- · 2020-05-26 17:18

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

查看更多
虎瘦雄心在
5楼-- · 2020-05-26 17:19

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

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

gl Paulo Bueno

查看更多
Animai°情兽
6楼-- · 2020-05-26 17:23

You can use IE conditional comment like this:

<!--[if IE]>
input#search{
  padding-top:3px;    /* adjust value */
}
<![endif]-->
查看更多
登录 后发表回答