vertical padding for input elements in webkit brow

2019-08-28 17:13发布

I am unable to set a vertical/top padding for the text/placeholder in input elements.

The following code will work in IE/Firefox/Opera, but not in Safari/Chrome:

CSS:

input
{
 border: 1px solid black;
 height: 100px;
 padding: 70px 25px 10px 25px;
 width: 300px;
}

HTML:

<input type="text" placeholder="Enter text here"/>

The webkit Developer Tools display the metrics as they should be, but the text is still in the middle of the input.

Something similar might be here (unanswered though).

3条回答
再贱就再见
2楼-- · 2019-08-28 17:39

I believe there is no way to set vertical padding in Webkit.

Use the height property, to add vertical padding. You may need to use line-height or padding-top/padding-bottom to vertically center the text across browsers.

查看更多
Juvenile、少年°
3楼-- · 2019-08-28 17:45

inputs are inline elements. Inline elements don't accept vertical padding.

add: display:block to your CSS, you will then have to add float:left and clear your floats afterwards.

查看更多
\"骚年 ilove
4楼-- · 2019-08-28 17:54

Just tested that and its bizzare how Chrome behaves. Could you maybe stick the input in a div and use padding on that?

查看更多
登录 后发表回答