Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change the CSS of a text input when selected?

Tags:

css

input

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?

like image 812
JSW189 Avatar asked Oct 17 '25 07:10

JSW189


2 Answers

Have you tried the focus pseudo-class

:focus 

more info: http://reference.sitepoint.com/css/pseudoclass-focus

like image 78
Mike Sav Avatar answered Oct 19 '25 22:10

Mike Sav


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.

like image 25
AK4668 Avatar answered Oct 19 '25 21:10

AK4668



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!