禁用焦点上的锚点 () 元素上的灰色边框
我试图让锚标签周围出现的丑陋的灰色边框消失。 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
不幸的是,我认为
hideFocus
是您最好的答案,因为模糊并不总是合适的: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:http://msdn.microsoft.com/en-us/library/ms533783(VS.85).aspx
听起来您正在谈论当您通过链接切换时出现的虚线边框。您有适用于 Firefox 的正确解决方案(概要:CSS 中没有)。我对 IE 使用的最佳解决方案是添加一个 onfocus 侦听器来删除焦点:
请查看此站点,了解如何在全局范围内执行此操作的示例: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:
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
除非我错过了正在讨论的虚线边框,否则大纲:无在 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!
对于 IE,您可以像这样使用 Javascript:
阅读更多:
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:
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/
这不行吗?
Does this not work?
a {outline:noneIE 8}
css 似乎在 Firefox、Chrome 和 IE 8 上运行良好。a {outline:noneIE 8}
css seems to work well on Firefox, Chrome and IE 8.