remove grey background on link clicked in ios safari / chrome / firefox

夙愿已清 提交于 2019-11-26 18:58:53

问题


When you click (touch) a link in Safari (or chrome or firefox) for iOS, you get a grey background behind link (only while you're holding it). Is there a way to remove this feature using CSS?

Please see the example image below:


回答1:


Webkit has a specific style property for that: -webkit-tap-highlight-color.

Copied from: http://davidwalsh.name/mobile-highlight-color—

/* light blue at 80% opacity */
html {
    -webkit-tap-highlight-color: rgba(201, 224, 253, 0.8);
}

/* change it for a div that has a similar background-color to the light blue tap color */
.blueDiv {
    -webkit-tap-highlight-color: rgba(251, 185, 250, 0.9);
}

If you want to remove the highlight completely—

.myButton {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}



回答2:


Latest versions of iOS are ignoring RGBA colors for some reason.

To remove it, I ended up having to use the following:

-webkit-tap-highlight-color: transparent;

As documented here: https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-tap-highlight-color



来源:https://stackoverflow.com/questions/11885161/remove-grey-background-on-link-clicked-in-ios-safari-chrome-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!