Files
2nd/10_Wiki/Topics/Frontend/CSS Media Queries.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

163 lines
4.4 KiB
Markdown

---
id: wiki-2026-0508-css-media-queries
title: CSS Media Queries
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Media Query, "@media"]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [css, responsive, media-query, frontend]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: CSS
framework: none
---
# CSS Media Queries
## 매 한 줄
> **"매 viewport / user preference 의 conditional CSS"**. Media Queries 는 device width, color scheme, motion preference 등 의 condition 의 styling 의 적용. 2026 Container Queries 의 출현 에도 viewport-level adaptation 의 표준.
## 매 핵심
### 매 query types
- **Width**: `min-width`, `max-width` — viewport 크기
- **Orientation**: `portrait`, `landscape`
- **User preference**: `prefers-color-scheme`, `prefers-reduced-motion`, `prefers-contrast`
- **Resolution**: `min-resolution: 2dppx` (Retina)
- **Hover capability**: `hover: hover` vs `hover: none`
- **Pointer**: `pointer: fine` vs `coarse`
### 매 Range syntax (2026 표준)
```css
@media (width >= 768px) { ... }
@media (400px <= width <= 800px) { ... }
```
### 매 Mobile-first vs Desktop-first
- **Mobile-first** (권장): base = mobile, `min-width` 의 add — 매 cascade 친화적
- **Desktop-first**: base = desktop, `max-width` 의 override — 매 legacy
### 매 응용
1. Responsive breakpoint.
2. Dark mode (`prefers-color-scheme`).
3. Accessibility (`prefers-reduced-motion`).
4. Print stylesheet (`@media print`).
5. High-DPI image (Retina).
## 💻 패턴
### Mobile-first breakpoints
```css
/* base: mobile */
.card { padding: 1rem; font-size: 14px; }
@media (width >= 640px) { .card { padding: 1.5rem; } }
@media (width >= 1024px) { .card { font-size: 16px; } }
@media (width >= 1440px) { .card { padding: 2rem; } }
```
### Dark mode
```css
:root {
--bg: #fff;
--fg: #111;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0a0a0a;
--fg: #f5f5f5;
}
}
body { background: var(--bg); color: var(--fg); }
```
### Reduced motion (a11y)
```css
.fade { transition: opacity 0.4s ease; }
@media (prefers-reduced-motion: reduce) {
.fade { transition: none; }
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
```
### Hover-only enhancements
```css
@media (hover: hover) and (pointer: fine) {
.btn:hover { background: #eee; transform: scale(1.02); }
}
```
### Print stylesheet
```css
@media print {
nav, .ads, .comments { display: none; }
body { font-size: 12pt; color: #000; background: #fff; }
a::after { content: " (" attr(href) ")"; }
}
```
### JS 의 matchMedia
```js
const dark = window.matchMedia('(prefers-color-scheme: dark)');
dark.addEventListener('change', (e) => {
document.documentElement.dataset.theme = e.matches ? 'dark' : 'light';
});
```
### Container Query (2026 표준, MQ 와 의 보완)
```css
.card-host { container-type: inline-size; }
@container (width >= 400px) {
.card { display: grid; grid-template-columns: 120px 1fr; }
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Viewport-level layout | Media Query |
| Component-level adaptation | Container Query |
| 사용자 preference (dark/motion) | `prefers-*` MQ |
| JS 의 query check | `matchMedia` |
| Print styling | `@media print` |
**기본값**: mobile-first + range syntax (`width >=`).
## 🔗 Graph
- 부모: [[Responsive Design]]
- 변형: [[컨테이너 쿼리 (Container Queries)|Container Queries]]
- 응용: [[Dark Mode]] · [[Accessibility (A11y)|Accessibility]]
- Adjacent: [[CSS Grid]] · [[Flexbox]] · [[CSS_Architecture_and_Styling|CSS Variables]]
## 🤖 LLM 활용
**언제**: responsive breakpoint, dark mode, a11y motion handling 의 generation.
**언제 X**: component-level adaptation (Container Query 의 사용).
## ❌ 안티패턴
- **Device-targeted MQ**: `iPhone`, `iPad` 의 device sniff — 매 width-based 의 사용.
- **너무 many breakpoints**: 5개 이상 의 maintenance hell — 매 3-4개 의 기본.
- **`prefers-reduced-motion` 의 무시**: a11y 위반.
- **`max-width` desktop-first**: cascade 의 복잡 — 매 mobile-first.
## 🧪 검증 / 중복
- Verified (MDN Media Queries, CSS Media Queries Level 4/5).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — MQ patterns + range syntax + container queries |