hover

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since December 2018.

hover CSS @media 可以根据用户的主要输入机制是否可以悬停在元素之上来应用样式。

语法

悬停功能指定为从下面列表中选择的关键字值。

none

主要输入机制无法悬停或不方便悬停(例如,当用户执行不方便的长按操作时,许多移动设备模拟悬停),或者没有主指示输入机制。

hover

主要输入机制可以方便地悬停在元素上。

示例

HTML

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

CSS

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

结果

规范

Specification
Media Queries Level 4
# hover

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
hover media feature

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

参见