CSS输入文本的输入字段文本颜色
问题描述:
我有一个输入字段,其中的文本颜色为黑色。 (我正在使用jquery.placeholder)让我们说,那里的文本是“电子邮件”CSS输入文本的输入字段文本颜色
当你点击这个字段,黑色占位符文本消失(感谢jquery.placeholder)。
任何输入到此字段的文本,我希望它变成红色,而当您取消选择此字段时,我希望它保持红色。
目前,说“电子邮件”的文字是黑色的,我输入的任何内容都是红色的,这很棒,但只要我取消选择,它就会变回黑色。谁能帮我?即使取消选中,我也希望文本保持红色。这里是我的代码
textarea:focus, input:focus {
color: #ff0000;
}
input, select, textarea{
color: #000;
}
答
改变你的第二个样式来此:
input, select, textarea{
color: #ff0000;
}
目前,您正在通过表单将焦点关闭后的文本更改为black
。上述补救措施。
另外,将正常状态样式置于样式表中:focus
和:hover
样式之前是一个好主意。这有助于防止这个问题。所以
input, select, textarea{
color: #ff0000;
}
textarea:focus, input:focus {
color: #ff0000;
}
答
取代:
input, select, textarea{
color: #000;
}
有:
input, select, textarea{
color: #f00;
}
或color: #ff0000;
答
我总是这样输入提示,就像这样:
<input style="color: #C0C0C0;" value="[email protected]"
onfocus="this.value=''; this.style.color='#000000'">
当然,如果你的用户在现场填写,改变重点,回来到外地,外地将再次清除。如果你这样做,确保这就是你想要的。 您可以通过设置一个信号灯,这样使它成为一个时间的事情:
<script language = "text/Javascript">
cleared[0] = cleared[1] = cleared[2] = 0; //set a cleared flag for each field
function clearField(t){ //declaring the array outside of the
if(! cleared[t.id]){ // function makes it static and global
cleared[t.id] = 1; // you could use true and false, but that's more typing
t.value=''; // with more chance of typos
t.style.color='#000000';
}
}
</script>
然后你<输入>场看起来是这样的:
<input id = 0; style="color: #C0C0C0;" value="[email protected]"
onfocus=clearField(this)>
好吧,我理解,但如果我改变我的第二个样式改为红色,那么原始的占位文字也会变为红色(而不是黑色)。那有意义吗? – John
是的。如果你需要文字先黑。将其设置为占位符插件。或者你可以使用一些额外的脚本来实现这一点。 –
感谢队友,我完全错过了宣告占位符风格,这是独立于输入框的风格! – John