开发者

Remove or disable focus border of browser via javascript

Does anybody know how to disable or manipulate the (in most browsers) dashed border of a dom-element if it has the focus in a tabindex order?

I want to build my own style for a focused element, but it would be great to use the existing feature, because with tabindex it is possible to bind keydown event to the dom开发者_运维问答-element.


Just make a CSS rule for the elements you want that have outline:none;


CSS trick:

:focus { outline: none; }


With Firefox 53.0, if I disable the outline with one of the proposed solution, Firefox displays the default one.

However, if I use a blank color, it doesn't detect that the outline is hidden:

input:focus{
   outline: 1px solid rgba(255,255,255,1);
}


input::-moz-focus-inner { border: 0; }


Classic way is set outline to none:

outline: none;

However, it didn't work anymore on higher version browser or FireFox. This trick work for me:

outline: 0px solid transparent;

LOL. In future, if it detected transparent, then just replace with a little tiny higher transparent:

outline: 0px solid rgba(0,0,0,0.001);

Some browsers, it was a boxshadow too:

outline:none !important;
outline-width: 0 !important;
box-shadow: none;
-moz-box-shadow: none;
-webkit-box-shadow: none;


a {
outline: 0;
}

a: hover,
a: active,
a: focus {
     outline: none;
}

input::-moz-focus-inner {
border: 0;
}


:focus state - Set the outline property to 0px solid transparent;


$(function() {
     $('a').click(function() { $(this).blur(); });
     $('input').click(function() { $(this).blur(); });
});

Don't use CSS disable focus: http://outlinenone.com/ This use other users.


Using jQuery you can do

$("#nav li a").focus(function(){
  $(this).blur();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜