Sass(SCSS)๋?
๊ธฐ์กด CSS์ ํ๊ณ
์ ํ์(Selector)์ ๋ถํ์ํ ์ฌ์ฉ
์ฐ์ฐ ยท ์กฐ๊ฑด ยท ๋ฐ๋ณต๋ฌธ ๋ถ๊ฐ
CSS ์ฝ๋์ ๊ธธ์ด ยท ๋ณต์ก์ฑ ์ฆ๊ฐ
CSS Preprocessor(์ ์ฒ๋ฆฌ๊ธฐ)
CSS ๋์ ์ ์ฌ์ฉํ๋ ๊ธฐ๋ฅ. ์ ์ฒ๋ฆฌ๊ธฐ๋ก ์์ฑํ๊ณ CSS๋ก
์ปดํ์ผ(Compile)
ํ์ฌ ๋์// styles.scss $primary-color: #fff; * { margin: 0 auto; box-sizing: border-box; color: $primary-color; }
/* styles.css(compiled) */ * { margin: 0 auto; box-sizing: border-box; color: #fff; }
CSS์ ํ๋ก๊ทธ๋๋ฐ์ ์ธ ์์(๋ณ์, ํจ์, ์์ ๋ฐ ์ค์ฒฉ ๋ฑ)๋ฅผ ์ ๋ชฉํ์ฌ CSS ๋ฌธ์ ์์ฑ์ ๋์
์ฅ์ : ์ฌ์ฌ์ฉ์ฑ, ๋ด์ฅ ํจ์ ์ฌ์ฉ(์์ฐ์ฑ ์ฆ๊ฐ), ์ ์ง ๊ด๋ฆฌ ์ฉ์ด
์์) Sass(SCSS), Less, Stylus ๋ฑ
Sass์ SCSS์ ์ฐจ์ด์
SCSS๊ฐ Sass์ ์์ ์งํฉ(Superset)
SCSS๊ฐ ๊ธฐ์กด CSS ๋ฌธ๋ฒ๊ณผ ๋ ์ ์ฌ(
{}
,;
์กด์ฌ)
Sass(SCSS)์ ์ฌ์ฉ
๋ณ์:
$
๊ธฐํธ๋ฅผ ํตํด ์์ฑ$primary-color: #fff; body { background-color: $primary-color; }
์ค์ฒฉ(Nesting): ์ ํ์(Selector) ์ค์ฒฉ ๊ฐ๋ฅ
nav { i { width: 100%; height: 100%; } ul { margin: 0; padding: 0; list-style: none; li { display: flex; flex-direction: column; align-items: center; } a { text-decoration: none; } } }
๋ชจ๋(Module): CSS snippet์ ๋ค๋ฅธ SCSS ํ์ผ์์ ์ฌ์ฉ ๊ฐ๋ฅ
// _module.scss $primary-color: #fff; * { margin: 0; box-sizing: border-box; } // styles.scss // No file extension(ํ์ผ ํ์ฅ์) @ use 'module'; .container { background-color: module.$primary-color; }
๋ฏน์ค์ธ(Mixins): ์ฌ์ฌ์ฉํ CSS ์ ์ธ์ ๊ทธ๋ฃนํํ์ฌ ์ฌ์ฉ
@mixin wh($width, $height) { width: $width; height: $height; } img { @include wh(100%, 50%); }
์์(Extend/ Inheritance)
%centering { display: flex; align-items: center; justify-content: center; } .p1 { @extend %centering; color: #ff622b; } .p2 { color: #106b06; }
์ฐ์ฐ์(Operators)
.container { width: 100%; } article { float: left; width: 600px / 960px * 100%; } aside { float: right; width: 300px / 960px * 100%; }
Reference
Last updated