any-hover

any-hover CSS 媒体特性 可以用来测试是否有任意可用的输入机制可以在元素上 hover。

语法

any-hover 使用下面列表的值作为关键字。

none
可用的输入机制里没有机制可以方便地 hover,或者不存在定点输入机制。
hover
一个或多个可用的输入机制可以方便地在元素上 hover。

示例

测试是否有输入机制可以 hover

HTML

<a href="#">Try hovering over me!</a>

CSS

@media (any-hover: hover) {
  a:hover {
    background: yellow;
  }
}

结果

规范

规范 状态 备注
Media Queries Level 4
any-hover
Candidate Recommendation Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
any-hover media featureChrome Full support 41Edge Full support 16Firefox Full support 64IE No support NoOpera Full support 28Safari Full support 9WebView Android Full support 41Chrome Android Full support 41Firefox Android Full support 64Opera Android Full support 28Safari iOS Full support 9Samsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support

更多资料