问题
I've run into a weird IE7 problem..
I have some standard CSS styled buttons with a background picture and a solid 1px blue border. They work as supposed except in IE7..
If I click inside a form element (textarea/input-field) it automatically adds a black border on my buttons.. Sometimes it also happends in other cases where elements are in focus/active..
You can see a simple example here

The thing is that I need the border on the buttons for styling reasons, so isn't there a way of disabling this behaviour in IE7 without removing the original border - either with CSS or jQuery?
回答1:
I blogged about this issue here: http://markmintoff.com/2012/01/remove-internet-explorer-black-border-around-button/
Essentially you can use the following style to remove the offending border simply and effectively.
input[type=submit],
input[type=reset],
input[type=button]
{
filter:chroma(color=#000000);
color:#010101;
}
回答2:
IE is highlighting the form's "default" button, the button that will be triggered if you press the enter key inside one of the form inputs. To disable the highlighting, you have a couple options:
- Make the save button
type="button"
instead oftype="submit"
, and handle the form submission by handling the button's click event in javascript. This was the answer to this related question (although ASP.NET is handling the javascript part behind the scenes). - Add a second
type="submit"
button as the first input in the form, then hide it with CSS. Note thatdisplay:none;
will not cut it, you need to hide it by positioning it off screen with something like:position: absolute; top: 0; left: -9999px;
. This was the answer to this related question.
回答3:
jquery: $('input[type="submit"]').focus().blur();
回答4:
javascript:
document.getElementById('save').focus();
document.getElementById('save').blur();
来源:https://stackoverflow.com/questions/8602544/black-border-on-ie7-buttons-on-textarea-input-focus