SCSS๋ Sassy CSS(๋ฉ์ง CSS)์ ์ค์๋ง์ด๊ณ SASS๋ Syntactically Awesome Style Sheets (๋ฌธ๋ฒ์ ์ผ๋ก ์งฑ ๋ฉ์ง ์คํ์ผ์ํธ)์ ์ค์๋ง์ด๋ค.
https://velog.io/@jch9537/CSS-SCSS-SASS
SCSS๋ CSS Preprocessor๋ก compile์ ํตํด css๋ก ๋ณํ๋๋ฉฐ ๊ทธ css๋ฅผ ํตํด html ์คํ์ผ์ ๊พธ๋ฏธ๊ฒ ๋๋ค.
compiler๋ node-sass, ruby-sass ๋ฑ์ด ์๋ค.
(๋ง์ฐฌ๊ฐ์ง๋ก ์ต์ํ์ง ์์ ๊ฒ๋ค์ ๋ํด์ ์ ๋ฆฌํ๋ ๋ฐฉํฅ์ผ๋ก ์์ฑํ๋ค.)
style๋ค์ ๊ตฌ๋ถํด์ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ ๊ธฐ๋ฅ
(์ฐธ๊ณ ๋ก ํ์ผ๋ช
์์ _
๋ฅผ ๋ถ์ด๋ ์ด์ ๋ compile ๋์์์ ์ ์ธํ๋ ค๊ณ ๋ถ์ด๋ ๊ฒ์ด๋ค.)
// _buttons.scss
// %๋ฅผ ์ ์ํ ํค์๋ ์์ ๋ถํ์ ์ฌ์ฉ
%button {
font-familiy: inherit;
margin: 10px 5px;
padding: 5px;
border-radius: 7px;
font-size: 12px;
font-weight: 700;
color: white;
background-color: black;
text-transform: uppercase;
}
...
// main.scss
@import "_buttons";
a {
@extend %button;
text-decoration: none;
}
@content ๊ธฐ๋ฅ์ ํตํด block์ ์ป์ ์ ์๊ณ , ๊ทธ๋ก ์ธํด responsive scss๋ฅผ ์ฝ๊ฒ ์ ์ฉํ ์ ์๋ค.
// _mixins.scss
$minIphone: 500px;
$maxIphone: 690px;
$minTablet: $minIphone + 1;
$maxTablet: 1120px;
@mixin responsive($device) {
@if $device == "iphone" {
@media screen and (min-width: $minIphone) and (max-width: $maxIphone) {
@content;
}
} @else if $device == "tablet" {
@media screen and (min-width: $minTablet) and (max-width: $maxTablet) {
@content;
}
} @else if $device == "iphone-l" {
@media screen and (max-width: $minIphone) and (max-width: $maxIphone) and (orientation: landscape) {
@content;
}
} @else if $device == "ipad-l" {
@media screen and (min-width: $minTablet) and (max-width: $maxTablet) and (orientation: landscape) {
@content;
}
}
}
...
// main.scss
@import "_mixins";
h1 {
color: red;
@include responsive("iphone") {
color: yellow;
}
@include responsive("iphone-l") {
font-size: 60px;
}
@include responsive("tablet") {
color: green;
}
}
์ ์ฉํ mixins๋ค์ ์ฐพ์์ ๊ฐ๋ฐํ๋ค๋ฉด ๋ ์์ํ๊ฒ ๊ฐ๋ฐ์ด ๊ฐ๋ฅํ ๊ฒ์ด๋ค.
์๋ฅผ ๋ค๋ฉด,
๋ฑ๋ฑ...