Css to control onfocus and onblur?
Is it possible to control say a textbox or a textarea's onfocus or onblur state through css only?
I mean i want the background color to change when the cursor is in the textbox, and change back when the user clicks somewhere else.
Status:
Open Oct 26, 2006 - 03:36 AM
css, Web Design, html
3answers
Answers
Oct 26, 2006 - 11:04 PM
HI David,
Hope the following will help you.
/* makes input elements yellow when focus is applied */
input:focus {background-color:yellow;}
:focus are known as dynamic pseudo-classes and can
theoretically be applied to any element. Unfortunately, only a few modern browsers such
as Firefox support this functionality.
Oct 27, 2006 - 03:39 PM
Thanks multani.sarbjit.
I didn't know the focus pseudo-class, but as it doesn't work in Internet Explorer, i had to use this instead:
where "focused" and "notfocused" are two classes in the stylesheet.
You'll get points anyway, since I learned something new :)
Oct 27, 2006 - 11:24 PM
Thanks David
Answer this question
Share Your Own Experience & Expertise
We look to ensure that every question is answered by the best people with relevant expertise and experience, the best answers include multiple perspectives. Do you have relevant expertise or experience to contribute your answer to any of these commonly asked questions?
Add New Comment