Chrome支持input[type=text]元素的占位符属性(其他元素可能也支持)。

但以下CSS对占位符的值没有任何作用:

输入[占位符]、[占位符],*[占位符]{颜色:红色!重要的}<input-type=“text”placeholder=“Value”>

但Value仍将保持灰色而不是红色。

是否有方法更改占位符文本的颜色?


当前回答

HTML的一部分:

 <form action="www.anything.com">
 <input type="text" name="name"
  placeholder="Enter sentence"/>
  </form>

我将展示如何通过CSS更改“Enter sentence”表达式的颜色:

  ::placeholder{
  color:blue;
   }

其他回答

在html文件中:

<input type="text" placeholder="placeholder" class="redPlaceHolder">

在css文件中:

.redPlaceHolder{
   color: #ff0000;
}

对于Bootstrap和Less用户,有一个mixin.placeholder:

// Placeholder text
// -------------------------
.placeholder(@color: @placeholderText) {
  &:-moz-placeholder {
    color: @color;
  }
  &:-ms-input-placeholder {
    color: @color;
  }
  &::-webkit-input-placeholder {
    color: @color;
  }
}

您可以将其用于输入和焦点样式:

input::-webkit-input-placeholder  { color:#666;}
input:-moz-placeholder  { color:#666;}
input::-moz-placeholder { color:#666;}
input:-ms-input-placeholder  { color:#666;}
/* focus */
input:focus::-webkit-input-placeholder { color:#eee; }
input:focus:-moz-placeholder { color:#eee } /* FF 4-18 */
input:focus::-moz-placeholder { color:#eee } /* FF 19+ */
input:focus:-ms-input-placeholder { color:#eee } /* IE 10+ */
<input type="text" class="input-control" placeholder="My Input">   

在头部添加以下CSS。

<style type="text/css">
    .input-control::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
                    color: red !important;
                    opacity: 1; /* Firefox */
    }
        
     .input-control:-ms-input-placeholder { /* Internet Explorer 10-11 */
                    color: red !important;
     }
        
     .input-control::-ms-input-placeholder { /* Microsoft Edge */
                    color: red !important;
     }
</style>

以下是参考链接。https://www.w3schools.com/howto/howto_css_placeholder.asp

Compass有一个开箱即用的混音器。

举个例子:

<input type="text" placeholder="Value">

在SCSS中使用指南针:

input[type='text'] {
  @include input-placeholder {
    color: #616161;
  }
}

有关输入占位符mixin,请参阅文档。