Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Input field text color of inputted text

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"

When you click on this field, the black placeholding text dissapears (thanks to 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; } 
like image 251
John Avatar asked Jul 12 '11 19:07

John


People also ask

How do you change the color of text in input?

<input type="text" placeholder="A red placeholder text..">

How do you give text a input type color in HTML?

The <input type="color"> defines a color picker. The default value is #000000 (black). The value must be in seven-character hexadecimal notation.

How do I change the color of text in CSS?

Changing Inline Text Color in CSS Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.


1 Answers

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

input, select, textarea{     color: #ff0000; }  textarea:focus, input:focus {     color: #ff0000; } 
like image 54
Jason Gennaro Avatar answered Oct 01 '22 16:10

Jason Gennaro