afish674 Posted February 22, 2012 Share Posted February 22, 2012 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 More sharing options...
birbal Posted February 22, 2012 Share Posted February 22, 2012 input[type=text]:focus you can specify the attributes which you need to style http://w3schools.com...ibute_value.asp Link to comment Share on other sites More sharing options...
afish674 Posted February 22, 2012 Author Share Posted February 22, 2012 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 More sharing options...
ShadowMage Posted February 22, 2012 Share Posted February 22, 2012 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 More sharing options...
afish674 Posted February 22, 2012 Author Share Posted February 22, 2012 Ah, got it now. I think i'll use the first method, as i'm not too fussed about focus colours on the ticks or radio's Cheers! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.