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.

We'd love to hear more about your role and the company you work for
Please help us by answering a few questions.

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

浏览器兼容性

参见