通过 javascript 删除或禁用浏览器的焦点边框

发布于 2024-09-04 17:42:55 字数 142 浏览 4 评论 0原文

如果 dom 元素具有 tabindex 顺序的焦点,有人知道如何禁用或操作(在大多数浏览器中)dom 元素的虚线边框吗?

我想为焦点元素构建自己的样式,但使用现有功能会很棒,因为使用 tabindex 可以将 keydown 事件绑定到 dom 元素。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

疯到世界奔溃 2024-09-11 17:42:55

只需为您想要的具有 outline:none; 的元素制定 CSS 规则即可

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

日暮斜阳 2024-09-11 17:42:55

CSS技巧:

:focus { outline: none; }

CSS trick:

:focus { outline: none; }
多情癖 2024-09-11 17:42:55

在 Firefox 53.0 中,如果我使用建议的解决方案之一禁用大纲,Firefox 将显示默认解决方案。

但是,如果我使用空白颜色,它不会检测到轮廓被隐藏:

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

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);
}
尤怨 2024-09-11 17:42:55
input::-moz-focus-inner { border: 0; }
input::-moz-focus-inner { border: 0; }
鹤舞 2024-09-11 17:42:55

经典方式是将outline设置为none:

outline: none;

但是,它在更高版本的浏览器或FireFox上不再起作用。
这个技巧对我有用:

outline: 0px solid transparent;

哈哈。将来,如果它检测到透明,则只需替换为稍微高一点的透明度:

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

某些浏览器,它也是一个盒子阴影:

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

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;
挽清梦 2024-09-11 17:42:55
a {
outline: 0;
}

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

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

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

input::-moz-focus-inner {
border: 0;
}
初与友歌 2024-09-11 17:42:55

:focus state - 将轮廓属性设置为0px纯透明;

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

私野 2024-09-11 17:42:55
$(function() {
     $('a').click(function() { $(this).blur(); });
     $('input').click(function() { $(this).blur(); });
});

不要使用 CSS 禁用焦点: http://outlinenone.com/ 这会使用其他用户。

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

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

時窥 2024-09-11 17:42:55

使用 jQuery 你可以做

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

Using jQuery you can do

$("#nav li a").focus(function(){
  $(this).blur();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文