Change an HTML5 input's placeholder color with CSS

后端 未结 30 3184
猫巷女王i
猫巷女王i 2020-11-21 04:36

Chrome supports the placeholder attribute on input[type=text] elements (others probably do too).

But the following CSS doesn\'t do anything

30条回答
  •  野性不改
    2020-11-21 04:48

    OK, placeholders behave differently in different browsers, so you need using browser prefix in your CSS to make them identical, for example Firefox gives a transparency to placeholder by default, so need to add opacity 1 to your css, plus the color, it's not a big concern most of the times, but good to have them consistent:

    *::-webkit-input-placeholder { /* WebKit browsers */
        color:    #ccc;
    }
    *:-moz-placeholder { /* Mozilla Firefox <18 */
        color:    #ccc;
        opacity:  1;
    }
    *::-moz-placeholder { /* Mozilla Firefox 19+ */
        color:    #ccc;
        opacity:  1;
    }
    *:-ms-input-placeholder { /* Internet Explorer 10-11 */
        color:    #ccc;
    }
    

提交回复
热议问题