禁用焦点上的锚点 () 元素上的灰色边框

发布于 2024-08-03 12:40:21 字数 603 浏览 6 评论 0原文

我试图让锚标签周围出现的丑陋的灰色边框消失。 CSS 属性 outline:none; 适用于 Firefox,但如何在 IE 中执行此操作?最好使用 CSS 表达式或 jQuery。顺便说一句,我并不担心可访问性。


根据您的建议,我发现这些是最好的解决方案:

  • jQuery(适用于 IE 浏览器):

    $('a').focus(function() {
        $(this).blur();
    });
    
  • 另一个 jQuery 选项(仅适用于 IE 浏览器):

    $('a').focus(function() {
        $(this).attr("hideFocus", "hidefocus");
    });
    
  • CSS(适用于所有其他强制显示轮廓的浏览器):

    a {
        概要:无;
    }
    

注意:某些浏览器(例如 Google Chrome)不会强制在焦点上显示轮廓。

I am trying to make the ugly grey border that appears around anchor tags go away. The CSS property outline:none; works for Firefox, but how can I do it in IE? Preferably using CSS expressions or jQuery. I'm not worried about accessibility BTW.


Based on your suggestions I found these to be the best solutions:

  • The jQuery (for IE browsers):

    $('a').focus(function() {
        $(this).blur();
    });
    
  • Another jQuery option (for IE browsers only):

    $('a').focus(function() {
        $(this).attr("hideFocus", "hidefocus");
    });
    
  • The CSS (for all other browsers that force an outline):

    a {
        outline: none;
    }
    

Note: Some browsers such as Google Chrome don't force an outline on focus.

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

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

发布评论

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

评论(7

扶醉桌前 2024-08-10 12:40:21

不幸的是,我认为 hideFocus 是您最好的答案,因为模糊并不总是合适的:

<a href="..." hidefocus="hidefocus">...</a>

http://msdn.microsoft.com/en-us/library/ms533783(VS.85).aspx

Unfortunately I think hideFocus is your best answer as blur isn't always appropriate:

<a href="..." hidefocus="hidefocus">...</a>

http://msdn.microsoft.com/en-us/library/ms533783(VS.85).aspx

薯片软お妹 2024-08-10 12:40:21

听起来您正在谈论当您通过链接切换时出现的虚线边框。您有适用于 Firefox 的正确解决方案(概要:CSS 中没有)。我对 IE 使用的最佳解决方案是添加一个 onfocus 侦听器来删除焦点:

<a href="" onfocus="this.hideFocus=true;">link</a>

请查看此站点,了解如何在全局范围内执行此操作的示例:http://codylindley.com/Javascript/223/hiding-the-browsers-focus-borders-应该-我-不应该-i

It sounds like you're talking about the dotted border that appears when you tab through links. You have the correct solution for Firefox (outline: none in the CSS). The best solution I've used for IE is to add an onfocus listener that removes focus:

<a href="" onfocus="this.hideFocus=true;">link</a>

Take a look at this site for an example of how you might do it globally: http://codylindley.com/Javascript/223/hiding-the-browsers-focus-borders-should-i-shouldnt-i

兮颜 2024-08-10 12:40:21

除非我错过了正在讨论的虚线边框,否则大纲:无在 Internet Explorer 8 中工作(至少对我来说)。相反,突然之间,一些超链接呈现为带有点状边框(我记得更改的唯一属性是包含链接的 h2 元素上的 display:inline ,之后出现了点状边框)。所以我加入了一个{大纲:无;在我的全局样式表中,噗,IE8 中不再有边框!

Unless I'm missing which dotted border is being discussed, outline:none works in Internet Explorer 8 (at least, for me). Rather all of a sudden some hyperlinks were rendering with a dotted border (the only attribute I remember changing is display:inline on an h2 element that contained a link, afterwards the dotted border appeared). So I threw in a { outline:none; } in my global stylesheet and poof, no more border in IE8!

爱的十字路口 2024-08-10 12:40:21

对于 IE,您可以像这样使用 Javascript:

<a href="..." onfocus="this.blur();">Click Here</a>

阅读更多:
http://www.htmlgoodies.com/beyond/javascript/article.php/ 3471171

对于 Firefox 和 Safari,outline:none 有效。

阅读更多:
http://css-tricks.com/removing-the-dotted-outline/< /a>

For IE, you can use Javascript like this:

<a href="..." onfocus="this.blur();">Click Here</a>

Read more:
http://www.htmlgoodies.com/beyond/javascript/article.php/3471171

For Firefox and Safari, outline:none works.

Read more:
http://css-tricks.com/removing-the-dotted-outline/

瞳孔里扚悲伤 2024-08-10 12:40:21
a {
  outline: 0 none !important;
  border: none;
}
a {
  outline: 0 none !important;
  border: none;
}
坦然微笑 2024-08-10 12:40:21

这不行吗?

a
{
   border: 0;
}

Does this not work?

a
{
   border: 0;
}
森林很绿却致人迷途 2024-08-10 12:40:21

a {outline:noneIE 8} css 似乎在 Firefox、Chrome 和 IE 8 上运行良好。

a {outline:noneIE 8} css seems to work well on Firefox, Chrome and IE 8.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文