How to vertical-align text on this input box for I

2019-03-26 00:31发布

I have this code :

<input type="text" class="contactInput" value="my string">

.contactInput
{
    border:0;
    margin:0;
    padding:0;
    background-color:#000000;
    color:#ffffff;
    height:22px;
    width:290px;
    padding-left:5px;
}

and I'd like to vertical-align it. Firefox and Chrome do it automatically (as IE9). With IE8 or 7 is in the top.

How can I do it with CSS?

3条回答
Juvenile、少年°
2楼-- · 2019-03-26 00:52

For webkit, its better to use paddings to avoid giant cursor, like that.

  line-height: 14px/*to enclose 13px font, override this if needed*/;
  height: 14px/*to enclose 13px font, override this if needed*/;
  /*Padding is needed to avoid giant cursor in webkit, which we get if
  height = line-height = 22px.*/
  padding: 6px 8px;
查看更多
劳资没心,怎么记你
3楼-- · 2019-03-26 01:00

There is a problem with line-height in Chrome. When inline-height == height then chrome on picking edit box displays large cursor. When you start typing cursor decreases. Possible solution is to use paddings (top & bottom). In your case:

height: 18px;
padding-top: 4px;
查看更多
相关推荐>>
4楼-- · 2019-03-26 01:07

Assuming you mean vertically align in the centre, you can use the line-height CSS property to do this. Simply set it to be the same as the height of the element.

查看更多
登录 后发表回答