--- id: howto-css-fixed-sidebar title: "How To - Fixed Sidebar" category: "Web_Recipes" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["sidenav CSS", "fixed side navigation"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.83 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["howto", "css", "w3schools", "layout", "position", "navigation", "sidebar"] raw_sources: ["https://www.w3schools.com/howto/howto_css_fixed_sidebar.asp"] applied_in: [] github_commit: "" --- # [[HOWTO CSS Fixed Sidebar]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Just like the fixed-top-menu recipe, this pattern requires the SAME manual "keep two numbers in sync" discipline β€” the sidebar's `width` and the main content's `margin-left` must match exactly, or the content either overlaps the sidebar (margin too small) or leaves an awkward gap (margin too large); `z-index: 1` is also added here specifically because the sidebar sits alongside scrollable content rather than above/below it, making stacking order collisions more likely than in the top/bottom fixed-menu case. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`position: fixed; top: 0; left: 0;`** β€” pins the sidebar to the left edge of the viewport. [S1] - **`z-index: 1`** β€” ensures the sidebar stays above other page content in stacking order. [S1] - **`overflow-x: hidden`** β€” prevents horizontal scrollbars from appearing inside the fixed sidebar. [S1] - **Matching `margin-left` on `.main`** β€” must equal the sidebar's declared `width` (e.g. both `160px`) to avoid overlap. [S1] - **Full-height vs. auto-height variants** β€” `height: 100%` makes the sidebar span the entire viewport height; omitting it lets the sidebar size to its own content instead. [S1] - **Small-screen responsiveness** β€” `@media screen and (max-height: 450px)` reduces padding/font-size on short viewports (not a width breakpoint β€” a HEIGHT breakpoint, unusual compared to most responsive recipes in this cookbook). [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Full example: `.sidenav { height: 100%; width: 160px; position: fixed; z-index: 1; top: 0; left: 0; background-color: #111; overflow-x: hidden; padding-top: 20px; } .sidenav a { padding: 6px 8px 6px 16px; color: #818181; display: block; } .main { margin-left: 160px; padding: 0px 10px; }`. [S1] - Short-viewport adjustment: `@media screen and (max-height: 450px) { .sidenav { padding-top: 15px; } .sidenav a { font-size: 18px; } }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ—†μŒ β€” μ‹ κ·œ λ ˆμ‹œν”Ό, κΈ°μ‘΄ λ¬Έμ„œμ™€ λͺ¨μˆœλ˜λŠ” λ‚΄μš© μ—†μŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) About/Services/Clients/Contact 링크가 λ‹΄κΈ΄ 쒌츑 κ³ μ • μ‚¬μ΄λ“œλ°”λ₯Ό λ§Œλ“€κ³ , 본문에 λ™μΌν•œ margin-leftλ₯Ό 쀘 κ²ΉμΉ˜μ§€ μ•Šκ²Œ ν•˜λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ 직접 μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Fixed sidebar with matching content margin (CSS): ```css .sidenav { height: 100%; width: 160px; position: fixed; z-index: 1; top: 0; left: 0; overflow-x: hidden; } .main { margin-left: 160px; /* must match sidenav width */ } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference) - **μ‹ λ’° 점수:** 0.83 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[W3Schools HOW TO]] - **κ΄€λ ¨ κ°œλ…:** [[HOWTO CSS Fixed Menu]], [[HOWTO JS Sidenav]], [[HOWTO CSS Sidebar Responsive]] - **μ°Έμ‘° λ§₯락:** CSS Layout & Positioning μ„Ήμ…˜. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” How To - Fixed Sidebar β€” https://www.w3schools.com/howto/howto_css_fixed_sidebar.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "How To - Fixed Sidebar" recipe (Astra wiki-curation, P-Reinforce v3.1 format).