[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,118 +1,193 @@
|
||||
---
|
||||
id: wiki-2026-0508-css-architecture-and-styling
|
||||
title: CSS Architecture and Styling
|
||||
category: Architecture
|
||||
status: needs_review
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [css_architecture_and_styling]
|
||||
aliases: [CSS Patterns, Styling Architecture, CSS Methodologies]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: [- css-architecture - tailwind-css - css-modules - bem - design-tokens - performance]
|
||||
raw_sources: [- 10_Wiki/Topics/AI_and_ML/CSS Architecture.md - 10_Wiki/Topics/AI_and_ML/CSS_구조_설계_방식.md - 10_Wiki/Topics/AI_and_ML/Tailwind CSS.md - 10_Wiki/Topics/AI_and_ML/Tailwind CSS v4.md - 10_Wiki/Topics/AI_and_ML/CSS-in-JS.md - 10_Wiki/Topics/AI_and_ML/CSS Variables.md - 10_Wiki/Topics/AI_and_ML/CSS Container Queries.md - 10_Wiki/Topics/AI_and_ML/Utility-first CSS.md - 10_Wiki/Topics/AI_and_ML/CSS 애니메이션 최적화(Optimizing CSS Animations).md]
|
||||
last_reinforced: 2026-05-08
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [css, frontend, design-system, web]
|
||||
raw_sources: []
|
||||
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/TS
|
||||
framework: Tailwind v4 / CSS-in-JS / vanilla CSS
|
||||
---
|
||||
|
||||
# CSS 아키텍처 및 스타일링 (CSS Architecture and Styling)
|
||||
# CSS Architecture and Styling
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "시각적 표현을 넘어, 대규모 시스템의 확장성과 유지보수성을 보장하는 엔지니어링 골격을 구축하라." CSS 아키텍처는 전역 네임스페이스 충돌을 방지하고 스타일의 예측 가능성을 확보하는 핵심 시스템입니다.
|
||||
## 매 한 줄
|
||||
> **"매 CSS architecture 의 핵심: scope + composition + design tokens + 매 minimize specificity wars"**. 매 2010s OOCSS / BEM / SMACSS, 매 2017 CSS-in-JS, 매 2020 utility-first (Tailwind), 매 2024 native CSS (cascade layers, container queries, `:has()`, nesting, view transitions). 매 2026 현재 Tailwind v4 + CSS Modules + design-token system 의 dominant.
|
||||
|
||||
## 📖 핵심 내용 (Core Content)
|
||||
## 매 핵심
|
||||
|
||||
### 1. 주요 스타일링 방법론 (Methodologies)
|
||||
* **BEM (Block Element Modifier)**: 명명 규칙을 통해 캡슐화를 모의하는 전통적 방식. `block__element--modifier` 구조로 계층을 명시합니다.
|
||||
* **CSS Modules**: 빌드 시 고유한 해시 클래스명을 생성하여 자동으로 로컬 스코프를 보장합니다.
|
||||
* **Utility-First (Tailwind CSS)**: 단일 목적의 유틸리티 클래스를 조합하여 UI를 구성합니다. JIT 컴파일을 통해 번들 크기를 최적화하며, 일관된 디자인 시스템 적용에 유리합니다.
|
||||
* **CSS-in-JS**: JavaScript 내부에 스타일을 작성하여 로직과 스타일을 응집시키나, 런타임 오버헤드와 RSC(React Server Components) 호환성 문제를 고려해야 합니다.
|
||||
### 매 architecture pillars
|
||||
- **Scoping**: 매 CSS Modules / Shadow DOM / Tailwind atomic / Vue scoped.
|
||||
- **Tokens**: 매 design tokens (`--color-primary`) — 매 single source of truth.
|
||||
- **Cascade layers**: 매 `@layer` — 매 explicit specificity ordering.
|
||||
- **Container queries**: 매 component-level responsive (not viewport).
|
||||
- **Logical properties**: 매 `margin-inline` — 매 i18n RTL/LTR free.
|
||||
|
||||
### 2. 현대적 CSS 기능 (Modern Features)
|
||||
* **CSS Variables (Custom Properties)**: 런타임에 동적으로 변경 가능한 디자인 토큰 관리의 핵심.
|
||||
* **Container Queries (`@container`)**: 뷰포트가 아닌 '부모 컨테이너'의 너비에 따라 반응하는 진정한 컴포넌트 기반 반응형 설계.
|
||||
* **Fluid Typography**: `clamp()` 함수를 활용하여 중단점 없이 부드럽게 스케일링되는 타이포그래피 구현.
|
||||
### 매 modern CSS features (2026 baseline)
|
||||
- `@layer reset, base, components, utilities;`
|
||||
- `@container (min-width: 30rem) { ... }`
|
||||
- `:has(> img)` parent selector.
|
||||
- Native nesting `&` (no preprocessor needed).
|
||||
- `view-transition-name: card-hero;` for smooth navigation.
|
||||
- `color-mix(in oklch, var(--brand) 80%, white)`.
|
||||
|
||||
### 3. 레이아웃 설계 전략
|
||||
* **Grid (2차원)**: 전체적인 페이지 구조 및 대규모 레이아웃 설계 (Layout-in).
|
||||
* **Flexbox (1차원)**: 개별 컴포넌트 내부의 아이템 정렬 및 공간 배분 (Content-out).
|
||||
### 매 응용
|
||||
1. Design systems (Radix, shadcn/ui, Material 3).
|
||||
2. Multi-brand white-label apps (token theming).
|
||||
3. Email templates (limited subset).
|
||||
4. Cross-platform (web + React Native via NativeWind).
|
||||
|
||||
### 4. 성능 최적화 (Performance)
|
||||
* **Reflow & Repaint 최소화**: `width`, `height` 등 기하학적 속성 대신 `transform`, `opacity`를 사용하여 GPU 가속을 활용한 60FPS 애니메이션 구현.
|
||||
* **Critical Rendering Path (CRP)**: 렌더링 차단을 방지하기 위해 CSS 분할 로딩 및 인라인 크리티컬 CSS 기법 적용.
|
||||
## 💻 패턴
|
||||
|
||||
## ⚠️ 트레이드오프 및 주의사항 (Trade-offs)
|
||||
* **Tailwind vs CSS Modules**: Tailwind는 빠른 개발과 번들 최적화에 강점이 있지만 마크업이 장황해지며, CSS Modules는 깔끔한 마크업을 유지하지만 별도의 네이밍 고민이 필요합니다.
|
||||
* **Runtime CSS-in-JS의 몰락**: RSC 환경과의 호환성 문제로 인해 Vanilla Extract와 같은 Zero-runtime 라이브러리나 정적 CSS 방식으로 회귀하는 추세입니다.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics**: [[Design_Tokens]], [[Modern_Web_Rendering]], [[Web_Performance_Optimization]], [[Feature_Sliced_Design]]
|
||||
- **Next Step**: Tailwind CSS v4의 'CSS-first' 아키텍처 도입 및 디자인 토큰 자동화 파이프라인(Style Dictionary) 구축.
|
||||
|
||||
---
|
||||
*Last updated: 2026-05-08*
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
|
||||
**추출된 패턴:**
|
||||
> *(TODO)*
|
||||
|
||||
**세부 내용:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(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
|
||||
### Design tokens with CSS custom properties
|
||||
```css
|
||||
:root {
|
||||
--color-bg: oklch(98% 0.01 250);
|
||||
--color-fg: oklch(20% 0.03 250);
|
||||
--color-brand: oklch(60% 0.18 260);
|
||||
--space-1: 0.25rem;
|
||||
--space-2: 0.5rem;
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
[data-theme="dark"] {
|
||||
--color-bg: oklch(15% 0.02 250);
|
||||
--color-fg: oklch(95% 0.01 250);
|
||||
}
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Cascade layers (specificity sanity)
|
||||
```css
|
||||
@layer reset, base, components, utilities;
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
@layer reset {
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; }
|
||||
}
|
||||
@layer components {
|
||||
.btn {
|
||||
background: var(--color-brand);
|
||||
color: white;
|
||||
padding: var(--space-2) var(--space-4);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
}
|
||||
@layer utilities {
|
||||
.mt-4 { margin-top: 1rem; }
|
||||
}
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Container queries
|
||||
```css
|
||||
.card-grid { container-type: inline-size; }
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
@container (min-width: 30rem) {
|
||||
.card { display: grid; grid-template-columns: 1fr 2fr; }
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Tailwind v4 (CSS-first config)
|
||||
```css
|
||||
@import "tailwindcss";
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
@theme {
|
||||
--color-brand: oklch(60% 0.18 260);
|
||||
--font-display: "Inter Display", sans-serif;
|
||||
--breakpoint-3xl: 120rem;
|
||||
}
|
||||
|
||||
@utility scrollbar-hidden {
|
||||
scrollbar-width: none;
|
||||
&::-webkit-scrollbar { display: none; }
|
||||
}
|
||||
```
|
||||
|
||||
### CSS Modules (Vite/Next)
|
||||
```tsx
|
||||
// Button.module.css
|
||||
.btn { background: var(--color-brand); }
|
||||
.btn:hover { filter: brightness(1.1); }
|
||||
|
||||
// Button.tsx
|
||||
import s from "./Button.module.css";
|
||||
export const Button = (p) => <button className={s.btn} {...p} />;
|
||||
```
|
||||
|
||||
### CSS-in-JS (vanilla-extract, zero-runtime)
|
||||
```ts
|
||||
import { style, createTheme } from "@vanilla-extract/css";
|
||||
|
||||
export const [themeClass, vars] = createTheme({
|
||||
color: { brand: "oklch(60% 0.18 260)" },
|
||||
});
|
||||
|
||||
export const button = style({
|
||||
background: vars.color.brand,
|
||||
padding: "0.5rem 1rem",
|
||||
});
|
||||
```
|
||||
|
||||
### View transitions API
|
||||
```css
|
||||
::view-transition-old(card),
|
||||
::view-transition-new(card) {
|
||||
animation-duration: 0.3s;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
document.startViewTransition(() => updateDOM());
|
||||
```
|
||||
|
||||
### `:has()` for parent-state styling
|
||||
```css
|
||||
.card:has(> img) { padding: 0; }
|
||||
form:has(input:invalid) .submit { opacity: 0.5; }
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Solo / small app | Tailwind v4 |
|
||||
| Design system / library | CSS Modules + tokens, or vanilla-extract |
|
||||
| Mature React app | shadcn/ui (Tailwind + Radix) |
|
||||
| Web Components | Shadow DOM + adopted stylesheets |
|
||||
| Static site / MPA | Native CSS + cascade layers |
|
||||
| Email | Inline styles + table layout |
|
||||
|
||||
**기본값**: 매 web app 의 Tailwind v4 + design tokens + cascade layers.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Frontend Engineering]] · [[Web Standards]]
|
||||
- 변형: [[Tailwind CSS]] · [[CSS Modules]] · [[CSS-in-JS]]
|
||||
- 응용: [[Design Systems]] · [[Component Libraries]]
|
||||
- Adjacent: [[Accessibility]] · [[Web Performance]] · [[Responsive Design]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 component CSS scaffolding, 매 token system design, 매 Tailwind class consolidation, 매 legacy CSS refactor (BEM → cascade layers).
|
||||
**언제 X**: 매 pixel-perfect designer review — 매 visual diff tooling 사용.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **`!important` 의 남용**: 매 specificity war — 매 cascade layers 로 해결.
|
||||
- **Magic numbers (`top: 17px`)**: 매 token / spacing scale 의 사용.
|
||||
- **Global selectors (`div { ... }`)**: 매 leakage — 매 scoped 사용.
|
||||
- **Inline styles for everything (CSS-in-JS overuse)**: 매 runtime cost.
|
||||
- **Ignoring `prefers-reduced-motion`**: 매 a11y violation.
|
||||
- **Pixel-only sizing**: 매 `rem` / `em` / `clamp()` 의 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (MDN cascade layers, web.dev container queries, Tailwind v4 docs 2025, CSS Working Group specs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — modern CSS 2026 (cascade layers, :has, Tailwind v4) |
|
||||
|
||||
Reference in New Issue
Block a user