docs(10_Wiki): Topic_Business/General/Graphic/Programming을 Topics/ 하위로 이동
최상위 10_Wiki/Topic_*였던 4개 카테고리 폴더를 10_Wiki/Topics/Topic_* 로 재배치. 콘텐츠 변경 없음(순수 폴더 이동) — Topics/ 하위 나머지 폴더는 이미 지난 커밋에서 전부 정리된 상태(잔존 항목은 에이전트 운영 상태 및 사용자가 보존을 요청한 업데이트0615/무제 3.canvas 뿐).
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
---
|
||||
id: css-variables-var
|
||||
title: "CSS Variables var()"
|
||||
category: "Frontend"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["CSS variables", "var() function", "custom properties", "CSS custom properties", "root variables", "--variable"]
|
||||
duplicate_of: ""
|
||||
source_trust_level: "B"
|
||||
confidence_score: 0.89
|
||||
created_at: 2026-06-23
|
||||
updated_at: 2026-06-23
|
||||
review_reason: ""
|
||||
merge_history: []
|
||||
tags: ["css", "web", "frontend", "w3schools", "variables", "custom-properties", "var"]
|
||||
raw_sources: ["https://www.w3schools.com/css/css3_variables.asp"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[CSS Variables var()]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
CSS variables (custom properties) are declared with a `--name` and read back with `var(--name)`; declaring them once in `:root` gives document-wide reusable values that make stylesheets easier to maintain and update. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **Global vs local** — global variables are declared in the `:root` selector for document-wide access; local variables are declared within a specific selector for limited scope. [S1]
|
||||
- **Naming rules** — variable names must begin with two dashes (`--`) and are case-sensitive. [S1]
|
||||
- **The var() function** — the syntax is `var(--name, value)`, where the name is required and `value` is an optional fallback. [S1]
|
||||
- **Why use them** — the main advantages are easier maintenance, improved readability, and simplified color updates across an entire page. [S1]
|
||||
|
||||
## 🧩 추출된 패턴 (Extracted patterns)
|
||||
- **Theme tokens in :root** — declaring colors as `:root` variables creates a single place to change a whole page's palette. [S1]
|
||||
- **Reuse via var()** — the same `var(--primary-bg-color)` reference reused across selectors keeps related values in sync. [S1]
|
||||
- **Fallback safety** — `var(--name, value)` supplies a default when the named variable is not defined. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
**Declaring variables** [S1]
|
||||
Global variables are declared in the `:root` selector; local variables within a specific selector. Names start with `--` and are case-sensitive:
|
||||
```css
|
||||
:root {
|
||||
--primary-bg-color: green;
|
||||
}
|
||||
|
||||
.note {
|
||||
--note-bg: yellow;
|
||||
}
|
||||
```
|
||||
|
||||
**The var() Function** [S1]
|
||||
The `var()` function is used to insert the value of a CSS variable. Its syntax is `var(--name, value)` — `--name` is the required variable name, and `value` is an optional fallback used if the variable is not found.
|
||||
|
||||
**Example — global variables used across selectors** [S1]
|
||||
```css
|
||||
:root {
|
||||
--primary-bg-color: #1e90ff;
|
||||
--primary-color: #ffffff;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--primary-bg-color);
|
||||
}
|
||||
|
||||
.container {
|
||||
color: var(--primary-bg-color);
|
||||
background-color: var(--primary-color);
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.container h2 {
|
||||
border-bottom: 2px solid var(--primary-bg-color);
|
||||
}
|
||||
|
||||
.container .note {
|
||||
border: 1px solid var(--primary-bg-color);
|
||||
padding: 10px;
|
||||
}
|
||||
```
|
||||
|
||||
**Example — swapping the color scheme by changing only the variables** [S1]
|
||||
```css
|
||||
:root {
|
||||
--primary-bg-color: #8FBC8F;
|
||||
--primary-color: #FFFAF0;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--primary-bg-color);
|
||||
}
|
||||
|
||||
.container {
|
||||
color: var(--primary-bg-color);
|
||||
background-color: var(--primary-color);
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.container h2 {
|
||||
border-bottom: 2px solid var(--primary-bg-color);
|
||||
}
|
||||
|
||||
.container .note {
|
||||
border: 1px solid var(--primary-bg-color);
|
||||
padding: 10px;
|
||||
}
|
||||
```
|
||||
|
||||
**Benefits** [S1]
|
||||
The page highlights three main advantages of CSS variables: easier maintenance, improved readability, and simplified color updates across entire pages.
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
The page's examples are the applied cases: a `:root` palette referenced by `body`, `.container`, `.container h2`, and `.container .note`, and a second version showing how changing only the `:root` values re-themes the entire layout. No external project/commit applications found in the source.
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Declare and use a global variable (language: CSS):
|
||||
```css
|
||||
:root {
|
||||
--primary-bg-color: #1e90ff;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--primary-bg-color);
|
||||
}
|
||||
```
|
||||
var() with fallback (language: CSS):
|
||||
```css
|
||||
.example {
|
||||
color: var(--name, value);
|
||||
}
|
||||
```
|
||||
|
||||
## ⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
|
||||
- **Global (`:root`) variables** — accessible through the entire document; use for site-wide theme tokens such as the primary palette. [S1]
|
||||
- **Local variables** — declared inside a specific selector and usable only within it; use when a value should only apply to one section. [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.89
|
||||
- **중복 검사 결과:** 신규 생성 (New discovery)
|
||||
|
||||
## 🔗 지식 그래프 (Knowledge Graph)
|
||||
- **상위/루트:** [[CSS Tutorial]]
|
||||
- **관련 개념:** [[CSS Overriding Variables]], [[CSS Colors]], [[CSS Selectors]], [[CSS Syntax]]
|
||||
- **참조 맥락:** Referenced when centralizing reusable values (colors, sizes) for maintainable, themeable stylesheets.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — CSS Variables var() — https://www.w3schools.com/css/css3_variables.asp
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-06-23: Initial draft synthesized from the W3Schools "CSS Variables var()" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user