I want to change the CSS of an <input type="text">
when the text box is selected; i.e. when the user clicks on the text box, I want different CSS rules to apply. Is there any way to do this using pure CSS?
Have you tried the focus pseudo-class
:focus
more info: http://reference.sitepoint.com/css/pseudoclass-focus
select the input fields which have attribute of text only
input[type="text"]:focus{background-color:yellow;}
Select any input field (checkbox,file,hidden,image,password,radio,reset,submit,text)
input:focus{background-color:yellow;}
Select any textarea
textarea:focus{background-color:yellow;}
OK that's by CSS however if you are looking to achieve smooth animated effects and have more control over focus/blur it is better to use JQuery or other JavaScript frameworks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With