Jump to content

Submit button - focus selector?


afish674

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

Thanks, this selector syntax works:

input[type=submit]:focus{background-color:#CCC;}

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.

input[type=submit]:focus{background-color:transparent;}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...