惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
博客园 - Franky
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
爱范儿
爱范儿
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
Microsoft Security Blog
Microsoft Security Blog
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
The CSS Media Query That Changed How I Approach Responsiv...
Aanshik Sharma · 2026-06-18 · via DEV Community

Aanshik Sharma

I was working on the responsiveness of my portfolio website when I discovered a CSS media query that changed how I think about responsive design.

I initially thought I needed a way to detect whether the website was being viewed on a mobile device or tablet.

I did that by checking if the height of the document body was greater than its width hoping it would be a reliable solution.

const isVertical= document.body.clientHeight > document.body.clientWidth;

I realized that I was checking the device’s portrait orientation instead of checking for the device type.

While researching the issue, I encountered this CSS media query that checks if the user’s primary input device can conveniently hover over DOM elements.

@media (hover: hover) {
    /* styles for devices that support hover */
}

Tailwind also supports this through arbitrary variants

<Card className="[@media(hover:hover)]:bg-teal-800" />

Devices that match

  • Desktops with mouse
  • Laptops with trackpad
  • Most devices with a mouse pointer

Devices that do not match

  • Touch-only phones
  • Touch-only tablets

However, devices with an attached mouse or trackpad may behave differently

For example,

.button{
    opacity: 1;
}

@media (hover: hover) {
    .button{
        opacity: 0;
    }

    .card:hover .button{
        opacity: 1;
    }
}

On mobile devices,

  • The button is always visible
  • :hover rules are ignored

On a laptop,

  • The button starts hidden
  • Appears when the card is hovered

This can also be used the other way around to explicitly check if the device is unable to hover over DOM elements.

@media (hover: none) {
    /* styles for devices that do not support hover */
}

or in tailwind as [@media(hover:none)]:bg-teal-800

Another useful media feature is @media (pointer: fine), which checks pointer precision of the primary pointing device. A table below describes how both the queries respond with primary input devices.

Device Hover Pointer
Mouse hover fine
Trackpad hover fine
Finger touch none coarse
Stylus usually hover; could be none depending on the device fine

Pointer characteristics are implementation-dependent and may vary across browsers and operating systems.

Since we have already discussed hover and pointer there are two important properties that I believe must be mentioned.

@media (any-hover: hover) {
    /* styles */
}

@media (any-pointer: fine) {
    /* styles */
}

These differ from

hover
pointer

because they consider all available inputs rather than just the primary one.

For example,

  • Tablet + mouse attached

might report

hover: none

but

any-hover: hover

This was a small discovery, but it changed the way I approach responsive design. If you're building interactions that depend on hover or pointer precision, these media queries are worth keeping in mind.