https://developer.mozilla.org/en-US/docs/Web/CSS/--*
ํํ์ด์ง ๋ง๋ค๋ฉด์ ๊ฒน์น๋ css style์์ฑ๋ค์ ํ๋์ฝ๋ฉํ์ง ๋ง๊ณ ์์๋ก ์ ์ ์ํด์ฃผ๋๋ก ํ์!
๋ํ css ๋ณ์๋ช ์ ์นด๋ฉ์ผ์ด์ค๋ก ์ฐ๊ธฐ ์๊ณ ๋ฐ์ (-)๋ก ๋จ์ด๋ค์ ์ฐ๊ฒฐํ๋ค.
ex) redBar (x)
ex) red-bar (O)
์์ฃผ ์ฐ๋ font-middle-size๋ฅผ 32px๋ก ํ์ฌ ์ด๊ฑธ ์์ํ ์์ผ์ ํ์ํ ๋ ๋ง๋ค ๊ฐ์ ธ๋ค ์ฐ๊ณ ์ถ๋ค๊ณ ๊ฐ์ ํ์,
๊ทธ๋ ค๋ฉด var ์ด๋ผ๋ css์์ ์ ๊ณตํด์ฃผ๋ ํจ์๋ฅผ ์ด์ฉํด์ผ ํ๋ค.
.red-viewer {
--font-size : 32px;
font-size : var(--font-size);
}
.red-viewer {
--font-size : 32px;
font-size : var(--font-size);
}
๋ํ..
.red-viewer {
--font-size : 32px; //๋ถ๋ชจ์ ์๋ ๋ณ์ ์ ์๋ ์์์ด ๋ฐ์ ์ธ ์ ์๋ค! (๋จ, ํ์ ๊ฐ์ ์๋จ)
}
.red-viewer li {
font-size : var(--font-size);
}
ํ์ง๋ง css์ ์์๋ค์ ์์ ๊ฐ์ด ์ง์ญ์ ์ผ๋ก ์ฐ์ง ์๊ณ ์ต์ root์ ์ ์ํด๋๋ค.
:root {
--font-size : 32px;
--background-color : thistle;
--base-space : 8px;
}
์ปฌ๋ฌ ์์ฃผ๋ก ๋ง์ด ํ์ฉํ๊ฒ ๋๋ค. ์ด๋ ๊ฒ ํ์ ๋์ ์ฅ์ ์ ์ต์๋จ ๋ฃจํธ์์ css ์์๊ฐ์ ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋๊น ๋ง์ฐ์คํ ์๋ค๊ฐ๋ค + ํค๋ณด๋ ๊ณ์ ๋๋๋ ค์ค ํ์๊ฐ ์๋ค๋ ๊ฒ!
ํ๋ฉด์ด ์์์ง ๋ ์์ ๊ฐ์ ๋ฐ๊ฟ์ฃผ๊ณ ์ถ๋ค๋ฉด ๋ฏธ๋์ด ์ฟผ๋ฆฌ์๋ค๊ฐ
๋ค๋ฅธ ์์ ๊ฐ์ ๋ณต๋ถํด์ ๋ฃ์ด์ฃผ๋ฉด ์๋ฐ๊ฐ ๋๋ค.
Custom properties (--*): CSS variables - CSS: Cascading Style Sheets | MDN
Property names that are prefixed with --, like --example-name, represent custom properties that contain a value that can be used in other declarations using the var() function.
developer.mozilla.org
:root {
--first-color: #16f;
--second-color: #ff7;
}
#firstParagraph {
background-color: var(--first-color);
color: var(--second-color);
}
#secondParagraph {
background-color: var(--second-color);
color: var(--first-color);
}
#container {
--first-color: #290;
}
#thirdParagraph {
background-color: var(--first-color);
color: var(--second-color);
}
https://developer.mozilla.org/en-US/docs/Web/CSS/calc
calc() - CSS: Cascading Style Sheets | MDN
The calc() CSS function lets you perform calculations when specifying CSS property values. It can be used anywhere a <length>, <frequency>, <angle>, <time>, <percentage>, <number>, or <integer> is allowed.
developer.mozilla.org
.foo {
--widthA: 100px;
--widthB: calc(var(--widthA) / 2);
--widthC: calc(var(--widthB) / 2);
width: var(--widthC);
}
'๋งํฌ์ > Html & Css' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[HTML ์ขํ] x, y, ox, oy, Height, width (0) | 2022.08.26 |
---|---|
[HTML][CSS] box model (0) | 2022.06.11 |
์นํ์ด์ง ์์ด์ฝ ๋ณ๊ฒฝํ๊ธฐ (0) | 2022.05.15 |
[css] png ํ์ผ ์ด๋ฏธ์ง๋ง ๋ณด์ด๊ฒ ์ฒ๋ฆฌํ๊ธฐ (0) | 2022.05.07 |
[css] ๋ก๊ณ ์ ๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด ์ฝ๊ฐ ์ปค์ง๋ ๊ท์ฌ์ด ์ ๋๋ฉ์ด์ (0) | 2022.05.07 |