--- id: css-structural-pseudo-classes title: "CSS Structural Pseudo-classes" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["structural pseudo-classes", ":first-child", ":lang", "nth-child", "position-based selectors", "tree-position selectors"] 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", "pseudo-classes", "selectors"] raw_sources: ["https://www.w3schools.com/css/css_pseudo_classes_structural.asp"] applied_in: [] github_commit: "" --- # [[CSS Structural Pseudo-classes]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Structural pseudo-classes select elements based on their position in the document tree, letting you target things like the first child or language-tagged elements without adding extra classes. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Definition** β€” Structural pseudo-classes select elements based on their position in the document tree. [S1] - **`:first-child`** β€” Matches an element that is the first child of another element. [S1] - **`:lang()`** β€” Used to select elements with a `lang` attribute set to the specified value. [S1] - **Position is relative to the parent** β€” selection depends on where the element sits among its siblings, not on a class or id. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **First-child targeting** β€” `selector:first-child` styles only the element that appears first inside its parent. [S1] - **Combining position with descent** β€” `p em:first-child` vs `p:first-child em` produce different results depending on which element the `:first-child` is attached to. [S1] - **Language-aware styling** β€” `:lang(code)` applies styles (e.g. quotation marks) only to elements carrying a matching `lang` value. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Introduction** [S1] Structural pseudo-classes select elements based on their position in the document tree. **The `:first-child` pseudo-class** [S1] The `:first-child` pseudo-class matches a specified element that is the first child of another element. Style all first child `

` elements: ```css p:first-child { color: blue; } ``` Style the first `` element in all `

` elements: ```css p em:first-child { color: blue; } ``` Style all `` elements in all first child `

` elements: ```css p:first-child em { color: blue; } ``` **The `:lang()` pseudo-class** [S1] The `:lang()` pseudo-class is used to select elements with a `lang` attribute with the specified value. Define quotation marks for `` elements with `lang="no"` (Norwegian): ```html

Some text A quote in a paragraph Some text.

``` **Other structural pseudo-classes** [S1] | Pseudo-class | Description | | --- | --- | | `:last-child` | Matches the last child of a parent | | `:nth-child(n)` | Matches the nth child of a parent | | `:nth-last-child(n)` | Matches the nth child from the end | | `:only-child` | Matches an element that is the only child | | `:first-of-type` | Matches the first element of its type | | `:last-of-type` | Matches the last element of its type | For a complete list, the source directs readers to the CSS Pseudo-classes Reference. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own applied examples are the `:first-child` rules (blue paragraphs / emphasized text) and the Norwegian `:lang(no)` quotation-mark demo. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) First-child selector (language: CSS): ```css p:first-child { color: blue; } ``` Language selector (language: CSS): ```css q:lang(no) { quotes: "~" "~"; } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (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 Pseudo-elements]], [[CSS Selectors]], [[CSS Combinators]] - **μ°Έμ‘° λ§₯락:** Referenced when targeting elements by their tree position instead of adding extra classes. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Structural Pseudo-classes β€” https://www.w3schools.com/css/css_pseudo_classes_structural.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Structural Pseudo-classes" page (Astra wiki-curation, P-Reinforce v3.1 format).