Placeholder text is not vertically centered in Safari

后端 未结 7 462
挽巷
挽巷 2021-02-02 08:30

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.

相关标签:
7条回答
  • 2021-02-02 08:50

    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 */
    
    0 讨论(0)
  • 2021-02-02 08:56

    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 */
    }
    
    0 讨论(0)
  • 2021-02-02 08:59

    -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.

    0 讨论(0)
  • 2021-02-02 09:05

    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.

    enter image description here

    0 讨论(0)
  • 2021-02-02 09:06

    For me this worked well:

    line-height: inherit;
    
    0 讨论(0)
  • 2021-02-02 09:08

    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.

    0 讨论(0)
提交回复
热议问题