Chrome支持input[type=text]元素的占位符属性(其他元素可能也支持)。
但以下CSS对占位符的值没有任何作用:
输入[占位符]、[占位符],*[占位符]{颜色:红色!重要的}<input-type=“text”placeholder=“Value”>
但Value仍将保持灰色而不是红色。
是否有方法更改占位符文本的颜色?
Chrome支持input[type=text]元素的占位符属性(其他元素可能也支持)。
但以下CSS对占位符的值没有任何作用:
输入[占位符]、[占位符],*[占位符]{颜色:红色!重要的}<input-type=“text”placeholder=“Value”>
但Value仍将保持灰色而不是红色。
是否有方法更改占位符文本的颜色?
当前回答
对于使用Bourbon的SASS/SCSS用户,它具有内置功能。
//main.scss
@import 'bourbon';
input {
width: 300px;
@include placeholder {
color: red;
}
}
CSS输出,您也可以抓取这部分并粘贴到代码中。
//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;
}
其他回答
<style>
::-webkit-input-placeholder {
color:red;
}
::-moz-placeholder {
color:red;
} /* firefox 22+ */
:-ms-input-placeholder {
color:red;
} /* ie10,11 */
input:-moz-placeholder {
color:red;
}
</style>
对于Bootstrap用户,如果您使用class=“form control”,则可能存在CSS特定性问题。您应该获得更高的优先级:
.form-control::-webkit-input-placeholder {
color: red;
}
//.. and other browsers
或者如果您使用的是Less:
.form-control{
.placeholder(red);
}
::占位符{颜色:红色;}<input-type=“text”placeholder=“Value”>
这个怎么样
<input type=“text”value=“placeholder text”onfocus=“this.style.color='#000';this.value=“”;“style=”颜色:#f00;" />
没有CSS或占位符,但您可以获得相同的功能。
将此CSS代码用于所有浏览器工作:
::placeholder{color:#ccc;}
**HTML**
<input class="form-control" placeholder="write Here..">