Placeholder font-size bigger than 16px

为君一笑 提交于 2019-12-02 20:17:48

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

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 */

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

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)

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

::placeholder{
overflow: visible;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!