Html CSS 更改文本框字体颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21692594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS Change textbox font color
提问by Rob Hopper
I've searched and searched but can't quite get this right. I have a text box on my site and in my CSS/HTML I defined it a class much like anything else and gave it a background image no problem. I decided I needed to change the font color but no matter what I do, it just doesn't work.
我已经搜索并搜索过,但不能完全正确。我的网站上有一个文本框,在我的 CSS/HTML 中,我将它定义为一个类,就像其他任何东西一样,并给它一个背景图像,没有问题。我决定我需要更改字体颜色,但无论我做什么,它都不起作用。
My text box CSS is:
我的文本框 CSS 是:
.tb1 {
background-color : #505050;
background-image: url(images/mb_btn2.jpg);
color: 0090ff;
border-style: none;
onfocus="this.value=''
}
...this doesnt seem to quite work.
...这似乎不太奏效。
I read someone else's response to a similar question that stated using
我阅读了其他人对类似问题的回答,该问题说明使用
onfocus="this.value=''
which didn't do anything, I then tried, a placeholder:
没有做任何事情,然后我尝试了一个占位符:
<input name="username" type="text" class="tb1" maxlength="24" placeholder="Username"/>
and this sort of worked. It put a blue "Username" in the textbox. but I then have to erase it to begin typing, AND when you type it still comes out black and not in the defined color.
这种工作。它在文本框中放置了一个蓝色的“用户名”。但是我必须擦除它才能开始打字,而且当你打字时它仍然是黑色的,而不是定义的颜色。
This is the form HTML:
这是表单 HTML:
<div id="login" class="login"><center>
<form action="login.php" method="post">
Username:<br><input name="username" type="text" class="tb1" placeholder="Username"<br/>
Password:<br><input class ="tb1" type="password" name="password" placeholder="Password"/><br />
<input class="tb1" type="submit" name="login" value="Login"/>
</form></center>
</div>
So what would work to change the color of my textbox? and/or clear it out when you click on it so "Username" or "Password" is cleared and you can enter your information without having to erase it yourself prior to input?...oh and the submit button too
那么什么可以改变我的文本框的颜色呢?和/或当您点击它时将其清除,以便清除“用户名”或“密码”,您可以输入您的信息而无需在输入之前自己擦除它?...哦,提交按钮也是如此
- Thanks
- 谢谢
回答by Amarnath Balasubramanian
<div id="login" class="login">
<form action="login.php" method="post">Username:
<br>
<input name="username" type="text" class="tb1" placeholder="Username"/> <br/>Password:
<br>
<input class="tb1" type="password" name="password" placeholder="Password" />
<br />
<input class="tb1" type="submit" name="login" value="Login" />
</form>
</div>
CSS
CSS
.login
{
width:250px;
margin:0px auto;
}
.tb1 {
background-color : #505050;
background-image: url(images/mb_btn2.jpg);
color: #0090ff;
border-style: none;
}
fiddle
小提琴
in your code you have used <center>
, dont use it, it has been deprecated.
在您使用过的代码中<center>
,不要使用它,它已被弃用。
回答by dimitry_n
Your hex color declaration is missing #
. Change it to color: #0090ff;
您的十六进制颜色声明丢失#
。将其更改为color: #0090ff;
回答by Rohit Kumar
Try This
尝试这个
I assume you want to change the color of the font when the user focus is on TextBox.
我假设您想在用户焦点位于 TextBox 上时更改字体的颜色。
.tb1 {
background-color : #505050;
background-image: url(images/mb_btn2.jpg);
color: RED;
border-style: none;
}
.tb1:focus {
background-color : #505050;
background-image: url(images/mb_btn2.jpg);
color: YELLOW;
border-style: none;
}