热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CSS输入输入文本的字段文本颜色-CSSInputfieldtextcolorofinputtedtext

Ihaveaninputfield,andthecolorofthetextinitisblack.(Imusingjquery.placeholder)Let

I have an input field, and the color of the text in it is black. (I'm using jquery.placeholder) Let's say the text in there is "E-Mail"

我有一个输入字段,其中的文本颜色为黑色。 (我正在使用jquery.placeholder)让我们说那里的文字是“电子邮件”

When you click on this field, the black placeholding text dissapears (thanks to jquery.placeholder).

当您单击此字段时,黑色占位文本消失(感谢jquery.placeholder)。

Any text inputted into this field, I want it to turn red, and when you deselect this field, I want it to stay red.

输入到此字段的任何文本,我希望它变为红色,当您取消选择此字段时,我希望它保持红色。

At the moment, the text saying "E-Mail" is black, and anything I type into is red, which is great, but as soon as i deselect, it goes back to black. Can anyone help me? I want the text to stay red, even after it's deselected. Here is my code

目前,“电子邮件”的文字是黑色的,我输入的任何内容都是红色的,这很棒,但是一旦取消选择,它就会变回黑色。谁能帮我?我希望文本保持红色,即使在取消选中后也是如此。这是我的代码

textarea:focus, input:focus {
    color: #ff0000;
}

input, select, textarea{
    color: #000;
}

4 个解决方案

#1


45  

Change your second style to this:

将您的第二种风格更改为:

input, select, textarea{
    color: #ff0000;
}

At the moment, you are telling the form to change the text to black once the focus is off. The above remedies that.

此时,您正在告诉表单在焦点关闭后将文本更改为黑色。以上补救措施。

Also, it is a good idea to place the normal state styles ahead of the :focus and :hover styles in your stylesheet. That helps prevent this problem. So

此外,最好将正常状态样式放在样式表中的:focus和:hover样式之前。这有助于防止这个问题。所以

input, select, textarea{
    color: #ff0000;
}

textarea:focus, input:focus {
    color: #ff0000;
}

#2


2  

I always do input prompts, like this:

我总是做输入提示,如下所示:

    

Of course, if your user fills in the field, changes focus and comes back to the field, the field will once again be cleared. If you do it like that, be sure that's what you want. You can make it a one time thing by setting a semaphore, like this:

当然,如果您的用户填写了该字段,更改焦点并返回该字段,该字段将再次被清除。如果你这样做,请确保这是你想要的。您可以通过设置信号量使其成为一次性事物,如下所示:

    

Your field then looks like this:

您的字段如下所示:

    

#3


0  

replace:

更换:

input, select, textarea{
    color: #000;
}

with:

有:

input, select, textarea{
    color: #f00;
}

or color: #ff0000;

或颜色:#ff0000;

#4


0  

To add color to an input, Use the following css code:

要为输入添加颜色,请使用以下css代码:

input{
     color: black;
}

推荐阅读
author-avatar
郑青青11_875
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有