[HTML&CSS] Colors , Variables
( UPDATE 2023 - 05 - 30 )
Colors
์์ ์ฒด๊ณ (color system)
1)
hexadecimal color
(16์ง์ ์ปฌ๋ฌ)
#2ecc71์ ๊ฐ์ ์์ ์ฝ๋
2)
rgb
(๋์์ด๋๋ค์ด ๋ง์ด ์)
๊ฐ๊ฐ red, green, blue๋ฅผ ์๋ฏธ.
rgb(0,140,200)์ ๊ฒฝ์ฐ์ red ๊ฐ์ด 0, green ๊ฐ์ด 140, blue ๊ฐ์ด 200์ด๋ผ๊ณ ์ดํดํ ์ ์๋ค.
3)
rgba
rgb์ ๋์ผํ์ง๋ง a๊ฐ ํฌํจ๋ ํํ.
'a(alpha)'๋ ํฌ๋ช ๋๋ฅผ ์๋ฏธ
0(ํฌ๋ช )~1(๋ถํฌ๋ช ) ์ฌ์ด์ ๊ฐ์ผ๋ก ์กฐ์ ํ ์ ์๋ค.
Variables (=custom property)
variables (=custom property)
css๋ฅผ ํ๋ก๊ทธ๋๋ฐ์ธ์ด์ฒ๋ผ ๋ณด์ด๊ฒ ํ๋ค.
์ ์๋ ์ผ์ผ์ด ๋ค ๋ฐ๋ณต์์ ์ ๋ํ ๊ฑธ ์ํํด์ผ ํ๋ค๋ฉด,
Variable(๋ณ์)๋ฅผ ์ฌ์ฉํด์ ์์ ๋์ ์ค์ฌ์ค ์ ์๋ค.
mozilla ๋ฌธ์์ ๋ฐ๋ฅด๋ฉด, variable์ IE๋ฅผ ์ ์ธํ๊ณ ๋ค ์ด์ฉ ๊ฐ๋ฅํ๋ค.
์๋ฅผ ๋ค๋ฉด,
div {color: #2ecc71}
p {color: #2ecc71}
์ํ์์, ๋ ๋ชจ๋์ ์์ ๋ฐ๊พธ๊ณ ์ถ๋ค๋ฉด ์ฐ๋ฆฌ๋ div์ p์ ์์ ์ฝ๋๋ฅผ ์ง์ฐ๊ณ , ๋ ๋ค์ ์ ๋ ฅํด์ผ ํ๋ค.
๊ทธ๋ฌ๋ variable์ ์ด์ฉํ๋ฉด ๋ ๊ฐ๋จํด์ง๋ค.
:root
์ ์ฅํ๊ณ ์ถ์ ์์ฑ์ ์์ฑ
:root ๋ผ๋ ์๋ฆฌ๋จผํธ์ ๋ณ์๋ฅผ ์ถ๊ฐํ๋ ๊ฒ.
:root๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชจ๋ document์ ๋ฟ๋ฆฌ๊ฐ ๋๋ค.
Variable(๋ณ์) ์์ฑํ๋ ๋ฐฉ๋ฒ
1) ์์
:root {
--main-color:#ff0000;
}
a {
color:var(--main-color);
}
2) ๊ธฐ๋ณธ ๋ํดํธ ๋ฐ์ค ์ค์
:root {
--default-border:1px solid var(--main-color);
}
.a {
border:var(--default-border);
}
์ถ์ฒ
๋ ธ๋ง๋ ์ฝ๋ ์ฝ์ฝ์ํก ํด๋ก ์ฝ๋ฉ