--- id: css-clear-and-clearfix title: "CSS Clear and Clearfix" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["clear", "clearfix", "clearfix hack", "CSS clear", "clear both", "float clearing"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "float", "clear", "layout"] raw_sources: ["https://www.w3schools.com/css/css_float_clear.asp"] applied_in: [] github_commit: "" --- # [[CSS Clear and Clearfix]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The `clear` property stops elements from wrapping around floated content, and the clearfix hack (an `::after` pseudo-element with `clear: both`) forces a container to expand to include its floated children. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **clear purpose** β€” the `clear` property specifies behavior for elements adjacent to floated content; it prevents elements from wrapping around or beside the floated content. [S1] - **none (default)** β€” allows floating on either side. [S1] - **left** β€” pushes the element below left-side floats. [S1] - **right** β€” pushes the element below right-side floats. [S1] - **both** β€” pushes the element below floats on both sides. [S1] - **inherit** β€” inherits the parent's clear value. [S1] - **clearfix problem** β€” when floated elements exceed their container's height, they overflow the container. [S1] - **clearfix solution** β€” use the `::after` pseudo-element to contain floats properly. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Drop below a float** β€” set `clear` (e.g. `clear: left`) on the next element to push it below the float instead of beside it. [S1] - **Clearfix hack** β€” add an `::after` pseudo-element with empty content, `clear: both`, and `display: table` to make a parent contain its floated children. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **The clear property** [S1] The `clear` property specifies behavior for elements adjacent to floated content. It prevents elements from wrapping around or beside the floated content. **Clear property values** [S1] | Value | Behavior | |-------|----------| | none | Allows floating on either side (default) | | left | Pushes element below left-side floats | | right | Pushes element below right-side floats | | both | Pushes element below floats on both sides | | inherit | Inherits parent's clear value | **Clear example** [S1] ```css div1 { float: left; } div2 { clear: left; } ``` **The clearfix hack** [S1] When floated elements exceed container height, they overflow. The clearfix solution uses the `::after` pseudo-element to contain floats properly. ```css .clearfix::after { content: ""; clear: both; display: table; } ``` **How it works** [S1] - `.clearfix::after` targets the pseudo-element generated after the element's content. - `content: ""` renders the pseudo-element despite having no visible content. - `clear: both` pushes following content below floated elements and expands the parent container. - `display: table` establishes a new block formatting context for containing floats. The page notes: "This clears both left and right floats, effectively pushing any following content below the floated elements, and forces the parent container to expand to include them." [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's applied examples are a `clear: left` element dropped below a left-floated sibling, and a `.clearfix` container that uses `::after { content: ""; clear: both; display: table; }` to expand around its floated children. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Push an element below a left float (language: CSS): ```css div1 { float: left; } div2 { clear: left; } ``` Clearfix hack to contain floats (language: CSS): ```css .clearfix::after { content: ""; clear: both; display: table; } ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) - **none** β€” default; element may sit beside floats. [S1] - **left / right** β€” drop the element below floats on that one side. [S1] - **both** β€” drop below floats on either side; used inside the clearfix hack. [S1] - **inherit** β€” take the parent's clear value. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Float]], [[CSS Overflow]], [[CSS Position Fixed and Absolute]] - **μ°Έμ‘° λ§₯락:** Referenced whenever floated elements must be cleared or a container must expand to contain its floats. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Clear and Clearfix β€” https://www.w3schools.com/css/css_float_clear.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Clear and Clearfix" page (Astra wiki-curation, P-Reinforce v3.1 format).