要移除手机上的蓝色叠加层,您可以使用以下方法之一:
-webkit-tap-highlight-color: transparent; /* transparent with keyword */
-webkit-tap-highlight-color: rgba(0,0,0,0); /* transparent with rgba */
-webkit-tap-highlight-color: hsla(0,0,0,0); /* transparent with hsla */
-webkit-tap-highlight-color: #00000000; /* transparent with hex with alpha */
-webkit-tap-highlight-color: #0000; /* transparent with short hex with alpha */
但是,unlike other properties,你不能用
-webkit-tap-highlight-color: none; /* none keyword */
在 DevTools 中,这将显示为“无效的属性值”或其他内容。
要在聚焦时移除蓝色/黑色/橙色轮廓,请使用以下命令:
:focus {
outline: none; /* no outline - for most browsers */
box-shadow: none; /* no box shadow - for some browsers or if you are using Bootstrap */
}
我删除 box-shadow 的原因是因为 Bootsrap(和一些浏览器)有时会将其添加到焦点元素中,因此您可以使用它来删除它。
但是如果有人用键盘导航,他们确实会很困惑,因为他们依靠这个大纲来导航。所以你可以替换它
:focus {
outline: 100px dotted #f0f; /* 100px dotted pink outline */
}
您可以使用 :hover 或 :active target taps on mobile,因此您可以使用它们来提供帮助。否则可能会令人困惑。
完整代码:
element {
-webkit-tap-highlight-color: transparent; /* remove tap highlight */
}
element:focus {
outline: none; /* remove outline */
box-shadow: none; /* remove box shadow */
}
其他信息:
- 如果您想自定义
-webkit-tap-highlight-color,则应将其设置为半透明颜色,以便在点击时不会隐藏下方的元素
- 请从焦点元素don't remove the outline,或为它们添加更多样式。
-
-webkit-tap-highlight-color 没有得到很好的浏览器支持并且不是标准的。您仍然可以使用它,但要小心!