Change an HTML5 input's placeholder color with CSS

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

    /* do not group these rules */
    *::-webkit-input-placeholder {
        color: red;
    }
    *:-moz-placeholder {
        /* FF 4-18 */
        color: red;
        opacity: 1;
    }
    *::-moz-placeholder {
        /* FF 19+ */
        color: red;
        opacity: 1;
    }
    *:-ms-input-placeholder {
        /* IE 10+ */
        color: red;
    }
    *::-ms-input-placeholder {
        /* Microsoft Edge */
        color: red;
    }
    *::placeholder {
        /* modern browser */
        color: red;
    }
     

    This will style all input and textarea placeholders.

    Important Note: Do not group these rules. Instead, make a separate rule for every selector (one invalid selector in a group makes the whole group invalid).

提交回复
热议问题