如何将占位符文本颜色更改为白色

时间:2017-06-22 00:23:04

标签: html css placeholder textcolor search-box

我想弄清楚如何将搜索框的占位符文本的颜色更改为白色,这是我的css: enter image description here

继承人html: enter image description here

1 个答案:

答案 0 :(得分:3)

您可以使用::placeholder伪类。



input {
  background-color: #907;
}

input::placeholder {
  color: #fff;
}

<input type="text" placeholder="Enter Description Here" />
&#13;
&#13;
&#13;

但是,它并非标准化,并且可能无法在所有浏览器中正常运行。

添加供应商前缀以获得更好的支持:

&#13;
&#13;
input {
  background-color: #907;
}

input::placeholder {
  color: #fff;
}

::-webkit-input-placeholder {  /* Chrome/Opera/Safari */
  color: #fff;
}
::-moz-placeholder {  /* Firefox 19+ */
  color: #fff;
}
:-moz-placeholder { /* Firefox 18- */
  color: #fff;
}
:-ms-input-placeholder {  /* Edge/IE 10+ */
  color: #fff;
}
&#13;
<input type="text" placeholder="Desciption" />
&#13;
&#13;
&#13;

重要提示:请勿对这些选择器进行分组,如this post中所述。

相关问题