Jump to content

Submit button - focus selector?


Recommended Posts

I have written some CSS so that when an element is selected it is highlighted:

input:focus, textarea:focus{background-color:#FFC;}

This works fine, however it also gives the background colour to the submit button when this is in focus. Is there a selector I could use to override this? I tried submit:focus but this is clearly wrong. Thanks!

Link to comment
Share on other sites


you can specify the attributes which you need to style http://w3schools.com...ibute_value.asp

Edited by birbal
Link to comment
Share on other sites

Thanks, this selector syntax works:


But it is still a different colour to the original button. Ideally I just want it to go back to the default. Is there a way to do this? I think the buttons change slightly depending on what browser you use anyway.


Doesn't work because it removes the original colour.

Link to comment
Share on other sites

Birbal was suggesting that you change your original selector to exclude the buttons. This is probably the only way to accomplish this as, AFAIK, there is no way to revert a buttons background to the default using CSS.

input[type=text]:focus, textarea:focus{

Of course, if you also want to target other types (password, radio, checkbox, etc.) you'll need to add those to the selector too. CSS3 has a :not selector, but older browsers do not support it (namely IE8 and down). If you don't care about those browsers, you can use this:

input:not([type=submit]):focus, textarea:focus{

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...