2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

:hover と メディアクエリ pointer, any-pointer, hover

Last updated at Posted at 2023-12-25

:hoverのふるまいを加えたいのはいわゆるパソコン(マウスデバイス)だけでいいので、そのあたりを判定するメディアクエリの pointer, any-pointer, hover を検証してみた。

検証に使ったのはMac(Chrome 120)、iPhone(Safari 17), Pixel6a(Android Chrome 120)。本来はiPadやAndroidタブレットにマウスつなげた場合とそうでない場合とか、Surfaceとかでも検証するといいよね。

See the Pen media pointer, any-pointer, hover by ksk1015 (@ksk1015) on CodePen.

https://developer.mozilla.org/ja/docs/Web/CSS/@media/pointer
https://developer.mozilla.org/ja/docs/Web/CSS/@media/any-pointer
https://developer.mozilla.org/ja/docs/Web/CSS/@media/hover

まとめ

hoverのふるまいを加えたいのは、ポインタが正確かどうか(fine)ではなく、hover状態が普通にあるデバイスかどうかで判定すべきなので、主にパソコンとスマホを想定したウェブサイトでパソコンのみhoverのふるまいをさせたい場合は、(hover: hover) で判定するのがいいのかな。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?