--- id: css-media-queries-examples title: "CSS Media Queries Examples" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["media query examples", "responsive layout examples", "responsive columns", "responsive navigation menu", "hide element responsive"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.87 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "media-queries", "responsive", "flexbox"] raw_sources: ["https://www.w3schools.com/css/css3_mediaqueries_ex.asp"] applied_in: [] github_commit: "" --- # [[CSS Media Queries Examples]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Media queries are a popular technique for delivering a tailored style sheet to different devices β€” switching background colors, reflowing columns, stacking navigation, hiding elements, and respecting user preferences at breakpoints. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Purpose** β€” media queries are a popular technique for delivering a tailored style sheet to different devices. [S1] - **Breakpoint-driven layout** β€” combining `@media` with flexbox lets grids change column counts and stack at smaller widths. [S1] - **Direction switching** β€” `flex-direction: column` inside a query converts horizontal navigation/columns into vertical stacks on small screens. [S1] - **Conditional visibility** β€” `display: none` inside a query hides elements below a width. [S1] - **Beyond width** β€” queries can target `orientation` and user preferences like `prefers-reduced-motion`. [S1] - The page directs readers to the Responsive Web Design Tutorial for deeper learning. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Mobile-first color tiering** β€” set a base style, then upgrade it at `min-width: 768px` and `min-width: 992px`. [S1] - **Reflowing flex grid** β€” `flex: 25%` columns drop to `flex: 50%` at `max-width: 992px`, then stack via `flex-direction: column` at `max-width: 600px`. [S1] - **Collapse-to-stack navigation** β€” a `display: flex` menu becomes vertical with `flex-direction: column` at `max-width: 600px`. [S1] - **Hide / resize at breakpoint** β€” `display: none` or a larger `font-size` keyed to a width. [S1] - **Preference-aware styling** β€” `orientation: landscape` and `prefers-reduced-motion: reduce`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) Media queries are a popular technique for delivering a tailored style sheet to different devices. The page presents several practical examples. [S1] **Example 1 β€” background color across breakpoints** [S1] ```css /* Base style for mobile devices */ body { background-color: olive; color: white; } /* For devices with a minimum width of 768px (Medium) */ @media screen and (min-width: 768px) { body { background-color: blue; color: white; } } /* For devices with a minimum width of 992px (Large) */ @media screen and (min-width: 992px) { body { background-color: tan; color: black; } } ``` **Example 2 β€” flexible columns layout** [S1] ```css * { box-sizing: border-box; } /* Container for flexboxes */ .container { display: flex; flex-wrap: wrap; } /* Create four equal columns */ .column { flex: 25%; padding: 20px; } /* On screens that are 992px wide or less, go from four columns to two columns */ @media screen and (max-width: 992px) { .column { flex: 50%; } } /* On screens that are 600px wide or less, make the columns stack on top of each other */ @media screen and (max-width: 600px) { .container { flex-direction: column; } } ``` **Example 3 β€” responsive navigation menu** [S1] ```css ul { list-style-type: none; margin: 0; padding: 0; background-color: #333333; display: flex; } ul li a { display: block; color: white; padding: 14px 16px; text-decoration: none; } ul li a:hover { background-color: #111111; } /* For viewport width 600px or less, make the menu links stack on top of each other */ @media screen and (max-width: 600px) { ul { flex-direction: column; } } ``` **Example 4 β€” hide elements** [S1] ```css /* Hide element if the viewport width is 600px or less */ @media screen and (max-width: 600px) { #div1 { display: none; } } ``` **Example 5 β€” change font size** [S1] ```css /* If viewport width is 600px or more, set font-size to 80px */ @media screen and (min-width: 600px) { #div1 { font-size: 80px; } } ``` **Example 6 β€” screen orientation** [S1] ```css @media only screen and (orientation: landscape) { body { background-color: lightblue; } } ``` **Example 7 β€” user preferences (reduced motion)** [S1] ```css @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } } ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's applied examples are: a tiered `body` background (olive β†’ blue at 768px β†’ tan at 992px); a four-column flex grid that becomes two columns at 992px and stacks at 600px; a horizontal nav that stacks vertically at 600px; hiding `#div1` below 600px; enlarging `#div1` font to 80px at 600px+; a landscape-orientation background; and a reduced-motion rule disabling animations/transitions. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Reflowing flex grid (language: CSS): ```css .container { display: flex; flex-wrap: wrap; } .column { flex: 25%; padding: 20px; } @media screen and (max-width: 992px) { .column { flex: 50%; } } @media screen and (max-width: 600px) { .container { flex-direction: column; } } ``` Respect reduced-motion preference (language: CSS): ```css @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.87 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Media Queries]], [[CSS Flexbox]], [[CSS Box Sizing]], [[CSS Variables in Media Queries]] - **μ°Έμ‘° λ§₯락:** Referenced for concrete responsive recipes β€” column reflow, menu stacking, conditional hiding, and preference-aware styling. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Media Queries Examples β€” https://www.w3schools.com/css/css3_mediaqueries_ex.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Media Queries Examples" page (Astra wiki-curation, P-Reinforce v3.1 format).