触摸/按光标对象时指示禁用蓝色高光:指针

Ula*_*ach 54 mobile html5 highlight touch css3

只要在Chrome中触摸了应用了光标:指针属性的Div,就会出现蓝色突出显示.我们怎样才能摆脱它呢?

我尝试过以下方法:

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
Run Code Online (Sandbox Code Playgroud)

但它们不会影响按下光标时的蓝色突出显示.

Ula*_*ach 89

-webkit-tap-highlight-color:  rgba(255, 255, 255, 0); 
Run Code Online (Sandbox Code Playgroud)

解决问题,因为它将高光颜色设置为透明.

资料来源:http://samcroft.co.uk/2012/alternative-to-webkit-tap-highlight-color-in-phonegap-apps/

  • `-webkit-tap-highlight-color:透明;` 也可以。 (15认同)

Obo*_*hin 72

据我所知,Vlad K的答案可能会导致某些Android设备出现问题.更好的解决方案:

-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-tap-highlight-color: transparent;
Run Code Online (Sandbox Code Playgroud)

  • 如果你无论如何都要用透明覆盖它,为什么要使用 rgba 声明呢?是否有 WebKit 版本不支持此属性上的透明关键字? (4认同)
  • @BoltClock。我真的在[MDN doc](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-tap-highlight-color)中找不到“透明”关键字。认为这不是标准。在回答这个问题之前,我已阅读[本文](http://phonegap-tips.com/articles/essential-phonegap-css-webkit-tap-highlight-color.html),**基督教库克(Cook **)的注释建议添加了此内容,因为他遇到了一些三星设备的问题。我认为这是特定设备的错误。 (2认同)

asi*_*ith 20

只需将此添加到您的样式表中,然后将class="no_highlights"属性添加到您希望应用此类的元素。

no_highlights{
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
Run Code Online (Sandbox Code Playgroud)

或者您可以通过删除类名并执行此操作来对所有元素全局执行此操作。

button,
textarea,
input,
select,
a{
 -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
 -webkit-tap-highlight-color: transparent;
 -webkit-user-select: none;
 -khtml-user-select: none;
 -moz-user-select: none;
 -ms-user-select: none;
  user-select: none;

}
Run Code Online (Sandbox Code Playgroud)

谢谢 :) 但无论如何。蓝色边框作为可访问性功能存在。它看起来很糟糕,但是,它可以帮助最需要它的人。

  • 请注意,您不应在 input/select/textarea 元素上使用 (-*-)user-select:none 。这给 iOS 上的 Safari 带来了很多麻烦;当尝试专注于这些元素时,最终没有键盘弹出操作。 (2认同)

Eri*_*tta 11

根据文档,您可以简单地执行以下操作:

-webkit-tap-highlight-color: transparent; /* for removing the highlight */
Run Code Online (Sandbox Code Playgroud)

它适用于 Android 版 Chrome 68 和 Windows 版 Chrome 80。


Leu*_*ria 10

添加到CSS

CSS

html {
   -webkit-tap-highlight-color: transparent;
}
Run Code Online (Sandbox Code Playgroud)

顺风

@layer base {
  html {
    -webkit-tap-highlight-color: transparent;
  }
}
Run Code Online (Sandbox Code Playgroud)