Skip to content

Media 查询

一句话解释

media 查询是 CSS feature 那个 applies 样式仅 当特定条件关于 device or viewport 是 met.

用大白话说

Media queries let you write CSS that only applies under certain conditions — like when the screen is a particular width, the device is in landscape mode, or the user prefers dark mode. This is the foundation of responsive web design.

The most common use is targeting screen widths: @media (最小值-宽度: 768px) applies styles only on screens 768px or wider. You can combine conditions with and, use commas for "or", and check features like orientation, resolution, and color scheme.

A "mobile-first" approach writes base styles for mobile and adds enhancements with 最小值-宽度 queries. A "desktop-first" approach starts with desktop styles and uses 最大值-宽度 queries to adapt for smaller screens.

示例

css
/* Base styles (mobile) */
.menu { display: none; }

/* Tablet and up */
@media (min-width: 768px) {
  .menu { display: block; }
}

menu 是隐藏 on mobile and shown on screens 768px or wider — mobile-首先 responsive 模式.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表