Change an HTML5 input's placeholder color with CSS

后端 未结 30 3832
猫巷女王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:43

    Cross-browser solution:

    /* all elements */
    ::-webkit-input-placeholder { color:#f00; }
    ::-moz-placeholder { color:#f00; } /* firefox 19+ */
    :-ms-input-placeholder { color:#f00; } /* ie */
    input:-moz-placeholder { color:#f00; }
    
    /* individual elements: webkit */
    #field2::-webkit-input-placeholder { color:#00f; }
    #field3::-webkit-input-placeholder { color:#090; background:lightgreen; text-transform:uppercase; }
    #field4::-webkit-input-placeholder { font-style:italic; text-decoration:overline; letter-spacing:3px; color:#999; }
    
    /* individual elements: mozilla */
    #field2::-moz-placeholder { color:#00f; }
    #field3::-moz-placeholder { color:#090; background:lightgreen; text-transform:uppercase; }
    #field4::-moz-placeholder { font-style:italic; text-decoration:overline; letter-spacing:3px; color:#999; }
    

    Credit: David Walsh

提交回复
热议问题