Placeholder font-size bigger than 16px

后端 未结 5 1295
不知归路
不知归路 2021-02-01 13:53

I have read a couple of articles about styling the placeholder of an input field using ::-webkit-input-placeholder in HTML5. It works perfectly, except for one thin

相关标签:
5条回答
  • 2021-02-01 14:17

    You have to add 'overflow: visible' to the placeholder in your css to get rid of the cropping.

    ::placeholder{
    overflow: visible;
    }
    
    0 讨论(0)
  • 2021-02-01 14:19

    input {
        width: 450px;
        padding: 0px 15px;
    }
    
    input,
    input::-webkit-input-placeholder {
        font-size: 25px;
        line-height: 4;
    }
    <input type="text" placeholder="My Cool Placeholder Text">

    0 讨论(0)
  • 2021-02-01 14:21

    Meanwhile, the browser vendors implemented the ::placeholder CSS pseudo-element.

    You can find the current state of browser compatibility on caniuse.com.

    Currently (2019-04-29) there are following notes:

    ::-webkit-input-placeholder for Chrome/Safari/Opera (Chrome issue #623345)

    ::-ms-input-placeholder for Edge (also supports webkit prefix)

    0 讨论(0)
  • 2021-02-01 14:29

    Placeholder styles will not resize an input field and will not affect its box model. Add font-size to your input to fix the placeholder from getting cut off.

    You also might consider adding placeholder styles for other browsers...

    ::-moz-placeholder {} /* Firefox 19+ */
    :-moz-placeholder {}  /* Firefox 18- */
    :-ms-input-placeholder {} /* IE */
    
    0 讨论(0)
  • 2021-02-01 14:37

    The input and its placeholder must have matching font styles

    input {
        width: 400px;
        padding: 0 20px;
    }
    
    input,
    input::-webkit-input-placeholder {
        font-size: 20px;
        line-height: 3;
    }
    <input type="text" placeholder="My Cool Placeholder Text">

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