简体   繁体   中英

Placeholder text is not vertically centered in Safari

Do you have any idea on how to get the placeholder attribute to vertically center in safari? Though when you start typing, the text is perfectly centred.

-Safari Solution-

I got stuck on this issue for a long time despite using

input::-webkit-input-placeholder { line-height:normal!important; }

It turns out that having a line-height in the immediate input element was breaking my input::webkit-input-placeholder line-height.

Solution extended:

I removed the line-height in my input style and it fixed my issue.

The easiest way is to use both the line-height and height CSS properties. Just give the text input a line-height with the same value as its height .

By the way, your live site looks okay to me in chrome 16.

在此处输入图片说明

For me the best solution is to use line-height:normal and hack for IE 8.

<input type="text" name="test_name" placeholder="Search">


input {
    height: 35px;
    line-height: normal;
    line-height: 32px\0/; /* for IE 8 */
}

Had this bug too. Setting line-height in ems fixed this for me. It looks the same in Chrome, Safari(desktop and iOS) and Firefox. and I added a \\9 trick to get vertical centering in IE. here's my css

height: 36px;       
line-height: 1.2em;
line-height: 26px\9; /*for IE */

Works fine for me:

<input type="text" name="first_name" placeholder="Search" style="height: 50px;">

在此处输入图片说明

Try changing this:

#register-block-fields input {
width: 230px;
height: 41px;
padding-left: 40px;
padding-right: 20px;
height: 41px; // Changed from line-height
color: #878787;
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
background: none;
}

对我来说,这很有效:

line-height: inherit;

None of the other answers worked for me, maybe because my input element is inside a flex box.

I ended up needing to specify a line-height in px - with a large value for the line-height compared with the default for input elements.

input[type="text"] { line-height: 32px; }

Feels like a hack, but it's the only thing I could get to work.

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