Text input placeholders not displaying in IE and Firefox

后端 未结 4 2105
予麋鹿
予麋鹿 2021-02-07 04:55

My text input placeholders refuse to display in IE and Firefox despite having used the -moz-placeholder attribute. This can be viewed on the contact page here if you are using F

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 05:06

    As luke2012 stated this happens when box-sizing: border-box; is being used on text type input fields. However this only happens when a fixed height is being used (such as in the Bootstrap framework) and there is too much top and bottom padding. Which not only prevents placeholder text from displaying but also input text as well in Firefox.

    I find that the better solution is to keep box-sizing: border-box; and to instead remove the top and bottom padding and increase the height to the total height that you want the input field to have (including any border).

    input[type="email"], input[type="password"], input[type="text"] 
    {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        height: 42px; // Increase height as required
        margin-bottom: 30px;
        padding: 0 20px; // Now only left & right padding
    }
    

    This keeps things more consistent and works well on frameworks such as Bootstrap.

    Alternatively, you could increase the fixed height or set height: auto; and adjust the top and bottom padding as required.

提交回复
热议问题