Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change font colour in textbox with CSS when value is typed into box

I have a text box, which acts as a search box on my page. I pre-populate the field with the word 'SEARCH' which has a default text colour of #D6D6D0.

Using CSS, is it possible to change the text colour to #FFFFFF when someone enters text in the box?

<input type="text" name="q" value="SEARCH" id="searchFieldText">

#searchFieldText {
    background: url("/images/crmpicco/search_bg3.png") no-repeat scroll 0 0 #000000;
    border: medium none;
    color: #D6D6D0;
    float: left;
    font-family: Arial,Helvetica,sans-serif;
    font-size: 10px;
    height: 21px;
    padding-left: 0;
    padding-top: 3px;
    width: 168px;
}
like image 684
crmpicco Avatar asked Jan 24 '13 14:01

crmpicco


People also ask

How do you put color in a textbox in CSS?

You can also use the RGB decimal equivalent or the color name. For example, if you change the textbox background color to say, blue, you could specify any one of the following: background-color:blue; , background-color:#0000FF; , background-color:rgb(0,0,255); .

How do I change the color of text in CSS style?

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

The focus pseudo class should work

#searchFieldText:focus {
    color: #fff;
}
like image 52
Jrod Avatar answered Sep 23 '22 23:09

Jrod