SCSS

Seoยท2020๋…„ 7์›” 21์ผ
0

Front-End

๋ชฉ๋ก ๋ณด๊ธฐ
16/21
post-thumbnail

๐Ÿ”ฅ SCSS

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 ๋“ฑ์ด ์žˆ๋‹ค.

(๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ต์ˆ™ํ•˜์ง€ ์•Š์€ ๊ฒƒ๋“ค์— ๋Œ€ํ•ด์„œ ์ •๋ฆฌํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์ž‘์„ฑํ•œ๋‹ค.)

1. @extend

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;
}

2. mixins @content

@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๋“ค์„ ์ฐพ์•„์„œ ๊ฐœ๋ฐœํ•œ๋‹ค๋ฉด ๋” ์ˆ˜์›”ํ•˜๊ฒŒ ๊ฐœ๋ฐœ์ด ๊ฐ€๋Šฅํ•  ๊ฒƒ์ด๋‹ค.

์˜ˆ๋ฅผ ๋“ค๋ฉด,

๋“ฑ๋“ฑ...

profile
๊ฐœ๋ฐœ๊ด€์‹ฌ์ž

0๊ฐœ์˜ ๋Œ“๊ธ€