Change an HTML5 input's placeholder color with CSS

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

    For SASS/SCSS user using Bourbon, it has a built-in function.

    //main.scss
    @import 'bourbon';
    
    input {
      width: 300px;
    
      @include placeholder {
        color: red;
      }
    }
    

    CSS Output, you can also grab this portion and paste into your code.

    //main.css
    
    input {
      width: 300px;
    }
    
    input::-webkit-input-placeholder {
      color: red;
    }
    input:-moz-placeholder {
      color: red;
    }
    input::-moz-placeholder {
      color: red;
    }
    input:-ms-input-placeholder {
      color: red;
    }
    

提交回复
热议问题