views:

60

answers:

3

Question is in the subject.

+4  A: 

You can use CSS pseudo-class selectors like this:

textarea:focus { background-color: red }

Note that this doesn't work IE7 and lower.

Otto Allmendinger
And my vote goes to Otto, for being first by 2 minutes :-) But I would like to add that `:focus` isn't supported by IE7 or lower (i know!). For IE7 and IE6 you will need to use the DOM events `onfocus`/`onblur`.
Andy E
The question says "textbox", though.
Phoexo
@Phoexo: You're arguing semantics, Otto's answer is still correct. A textarea is a multi-line text box. An input with `type="text"` is a single-line text box.
Andy E
@Andy: thanks for the info, edited my answer
Otto Allmendinger
+4  A: 

Demonstration :)

textarea:focus
{
   background-color: #00ff00;
}
Sarfraz
+3  A: 
input[type='text']:focus {  
    background-color: #0066FF;  
}
Phoexo
does this work on ie6, 7 ?
ooo
Definitely not IE6. Possibly IE7, but I doubt it.
Dan Herbert
@oo: As I mentioned in my comment on Otto's answer, this only works on IE8 in standards mode, it will not work in IE8 compatibility mode, IE7 or lower. The workaround is to use javascript.
Andy E