简体   繁体   中英

Vertically center text in text input in Internet Explorer

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.

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

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

You can use IE conditional comment like this:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM