CSS 如何摆脱 Chrome/Safari 上的文本框选择突出显示?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3779577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:50:15  来源:igfitidea点击:

How to get rid of text box selection highlight on Chrome/Safari?

css

提问by Chris

When using Chrome or Safari, an active text boxor text areawill display a blue/orange borderaround the box. I have seen some sites get rid of this, but I have copied their CSSand it's still there. How do I do it?

使用 Chrome 或 Safari 时,active text boxtext areaborder在框周围显示蓝色/橙色。我已经看到一些网站摆脱了这一点,但我已经复制了它们CSS并且它仍然存在。我该怎么做?

回答by David says reinstate Monica

The following CSS usually removes the default highlight-border:

以下 CSS 通常会删除默认的高亮边框:

input:focus {outline: none; }

It's worth remembering that the outline is a useful visual feedback for the UI focus, for those users not using a mouse (keyboard navigation, for example), and it's worth substituting another visual cue to replace the loss of the outline.

值得记住的是,轮廓是 UI 焦点的有用视觉反馈,对于那些不使用鼠标的用户(例如键盘导航),值得用另一个视觉提示代替轮廓的丢失。

回答by Yi Jiang

You can use

您可以使用

input:focus, textarea:focus {
    outline: 0;
}

But try to give some indication to the user that the form element is focused, for accessibility reasons.

但是为了可访问性的原因,尝试向用户提供一些关于表单元素是焦点的指示。

回答by ericmackey

I just did this :

我只是这样做:

:focus { outline: none; }