[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,102 +2,155 @@
|
||||
id: wiki-2026-0508-css-grid
|
||||
title: CSS Grid
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: []
|
||||
aliases: [Grid Layout, CSS Grid Layout]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
tags: [uncategorized]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [css, layout, frontend]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-08
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: css
|
||||
framework: none
|
||||
---
|
||||
|
||||
# [[CSS Grid|CSS Grid]]
|
||||
# CSS Grid
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
CSS Grid는 행(Row)과 열(Column)을 동시에 다루어 복잡하고 체계적인 웹 페이지 구조를 설계할 수 있도록 돕는 2차원 레이아웃 시스템입니다 [1, 2]. [[Flexbox|Flexbox]]와 달리 레이아웃 구조를 먼저 정의하고 요소를 배치하는 '레이아웃 우선(layout in)' 방식을 취하며, 대규모 페이지 레이아웃이나 대시보드, 갤러리 등 정밀한 배치가 필요한 곳에 가장 적합합니다 [3-5].
|
||||
## 매 한 줄
|
||||
> **"매 2D layout 의 native primitive"**. CSS Grid 매 row + column 동시 control 의 layout system — 매 Flexbox 의 1D 보완. 매 2026 현재 매 모든 modern browser 매 stable, 매 `subgrid` + `masonry` (experimental) 까지 지원, 매 page-level 부터 component-level 까지 default tool.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **2차원 레이아웃 제어:**
|
||||
* 1차원(행 또는 열)으로만 작동하는 Flexbox와 다르게, CSS Grid는 가로와 세로 두 방향의 레이아웃을 동시에 제어할 수 있습니다 [2, 6].
|
||||
* 복잡한 중첩 컨테이너를 생성할 필요 없이 깔끔한 마크업으로 복잡한 디자인(예: 헤더, 푸터, 사이드바, 메인 콘텐츠 배치)을 쉽게 구현할 수 있습니다 [7, 8].
|
||||
* **정밀한 배치 및 오버랩(Overlap):**
|
||||
* `grid-template-columns`, `grid-template-rows`, `grid-template-areas` 등의 속성을 통해 아이템을 원하는 위치에 정확히 배치할 수 있습니다 [9, 10].
|
||||
* `grid-column` 및 `grid-row` 속성을 활용해 복잡한 마진이나 절대 위치 지정(Absolute positioning) 없이도 요소들을 겹치게 만들 수 있어 시각적인 계층을 표현하는 데 유리합니다 [11, 12].
|
||||
* **강력한 반응형 설계 기능:**
|
||||
* 여백 제어용 `gap`(`grid-gap`) 속성을 네이티브로 지원하므로 margin과 관련된 부작용을 방지합니다 [6, 12].
|
||||
* `fr`(분수) 단위와 `minmax()` 함수, 그리고 `repeat(auto-fit, ...)` 같은 기능을 결합하여, 미디어 쿼리에 크게 의존하지 않고도 가용 공간에 따라 트랙 수가 동적으로 변하는 유연한 반응형 레이아웃을 구현할 수 있습니다 [13-17].
|
||||
* **다른 CSS 기능과의 상호작용:**
|
||||
* **절대 위치 지정:** Grid 컨테이너에 `position: relative`를 주면 내부의 절대 위치(`position: absolute`) 요소가 전체 그리드 또는 할당된 그리드 영역(Grid Area)을 기준으로 정밀하게 배치될 수 있습니다 [18-20].
|
||||
* **`display: contents` 활용:** Grid 항목의 래퍼(Wrapper) 요소에 `display: contents`를 적용하면, 해당 래퍼의 박스는 사라지고 내부 자식 요소들이 직접 Grid 시스템의 항목으로 편입되어 그리드의 정렬 규칙을 따르게 됩니다 [21-23].
|
||||
* **실무 유지보수를 위한 설계 전략 (Flexbox와의 조합):**
|
||||
* 모던 프론트엔드 아키텍처에서는 CSS Grid와 Flexbox 중 하나만 선택하는 것이 아니라, 목적에 맞게 두 가지를 혼용하는 것이 핵심입니다 [24, 25].
|
||||
* 전체 페이지의 구조(Major layout)나 대규모 뼈대는 2차원인 **CSS Grid**로 잡고, 해당 셀 내부에 들어가는 UI 컴포넌트들의 세부적인 정렬은 1차원인 **Flexbox**로 처리하는 것이 유지보수성 높은 코드를 작성하는 모범 사례입니다 [26-29].
|
||||
## 매 핵심
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[Flexbox|Flexbox]], [[반응형 디자인|반응형 디자인]]
|
||||
- **Projects/Contexts:** 유지보수 가능한 CSS 레이아웃 설계, 웹 페이지 및 대시보드 구조화
|
||||
- **Contradictions/Notes:** Flexbox는 콘텐츠의 크기를 기반으로 공간을 분배하는 '콘텐츠 우선(content out)' 방식으로 동작하지만, CSS Grid는 정의된 레이아웃의 형태에 요소를 끼워 맞추는 '레이아웃 우선(layout in)' 방식을 취합니다 [5, 30]. CSS Grid가 더 복잡한 기능을 제공하지만 단순한 1차원 정렬(행, 열 내에서의 아이템 정렬)에 사용하기에는 과도한 설정(overkill)이 될 수 있으므로 상황에 맞게 Flexbox와 구별해 사용해야 합니다 [6, 27, 31].
|
||||
### 매 모델
|
||||
- **Grid container** (`display: grid`) — 매 parent.
|
||||
- **Grid items** — 매 direct children, 매 line-based positioning.
|
||||
- **Tracks** — rows + columns, 매 `fr` unit (fractional space) + `minmax()` + `auto`.
|
||||
- **Areas** — 매 named regions, 매 semantic layout description.
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-26*
|
||||
### 매 vs Flexbox
|
||||
- **Grid**: 매 2D (row + column 동시), 매 layout-first (parent decides).
|
||||
- **Flexbox**: 매 1D (single axis), 매 content-first (children sizing).
|
||||
- 매 함께 mix — 매 outer Grid + inner Flex 매 common.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 응용
|
||||
1. Page layout (header / sidebar / main / footer).
|
||||
2. Card grid 매 responsive (`auto-fill` + `minmax`).
|
||||
3. Dashboard 매 named-area complex layout.
|
||||
4. Image gallery 매 masonry.
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
|
||||
- **과거 데이터와의 충돌:** 없음
|
||||
- **정책 변화:** 없음
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
### Holy Grail layout
|
||||
```css
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-columns: 200px 1fr 200px;
|
||||
grid-template-rows: auto 1fr auto;
|
||||
grid-template-areas:
|
||||
"header header header"
|
||||
"nav main aside"
|
||||
"footer footer footer";
|
||||
min-height: 100vh;
|
||||
}
|
||||
.header { grid-area: header; }
|
||||
.nav { grid-area: nav; }
|
||||
.main { grid-area: main; }
|
||||
.aside { grid-area: aside; }
|
||||
.footer { grid-area: footer; }
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Responsive card grid (`auto-fill`)
|
||||
```css
|
||||
.cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
```
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Subgrid (nested alignment)
|
||||
```css
|
||||
.outer {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 16px;
|
||||
}
|
||||
.card {
|
||||
display: grid;
|
||||
grid-template-rows: subgrid; /* inherit parent row tracks */
|
||||
grid-row: span 3;
|
||||
}
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Line-based placement
|
||||
```css
|
||||
.item {
|
||||
grid-column: 2 / span 3; /* col 2 to 4 */
|
||||
grid-row: 1 / -1; /* full height */
|
||||
}
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### Masonry (2026 experimental)
|
||||
```css
|
||||
.gallery {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
grid-template-rows: masonry; /* Firefox + Safari TP */
|
||||
gap: 8px;
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Implicit grid + `dense` packing
|
||||
```css
|
||||
.feed {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
grid-auto-flow: dense; /* fill holes */
|
||||
grid-auto-rows: 100px;
|
||||
}
|
||||
.feed > .featured {
|
||||
grid-column: span 2;
|
||||
grid-row: span 2;
|
||||
}
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Page-level 2D layout | **Grid** |
|
||||
| Component 매 1D row/column | Flex |
|
||||
| Aligned nested grids | **Grid + subgrid** |
|
||||
| Dynamic content count, fluid wrap | Grid `auto-fill` |
|
||||
| Dense irregular packing | Grid `auto-flow: dense` |
|
||||
|
||||
**기본값**: 매 layout-first 결정 — Grid. 매 content-first sizing — Flex.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[CSS]] · [[Layout]]
|
||||
- 변형: [[Flexbox]] · [[Subgrid]] · [[Container Queries]]
|
||||
- 응용: [[Responsive Design]] · [[Dashboard]]
|
||||
- Adjacent: [[CSS Grid 및 Flexbox]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 2D layout, named areas semantic intent, responsive 매 `auto-fill`.
|
||||
**언제 X**: 1D 매 simple row of buttons — Flexbox 가 더 ergonomic.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **모두 1D 에 Grid 매 사용**: 매 Flex 보다 verbose.
|
||||
- **Pixel-only tracks**: 매 `fr` + `minmax` 매 사용 — 매 fluid.
|
||||
- **`!important` 으로 children 매 overriding**: 매 grid-area 매 misaligned signal.
|
||||
- **Subgrid 매 ignore**: nested grids 매 line-up 가 필요할 때 매 `subgrid` 가 정답.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (MDN CSS Grid Layout 2026, CSS Working Group Level 3).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Grid 2D layout + subgrid + masonry + responsive patterns |
|
||||
|
||||
Reference in New Issue
Block a user