1 ๋ถ„ ์†Œ์š”

Sass(Scss) ์•Œ์•„๋ณด๊ธฐ๐Ÿ‡

๐Ÿณ๏ธ Sass(Scss) : CSS Preprocessor(CSS ์ „์ฒ˜๋ฆฌ๊ธฐ)๋ผ ๋ถˆ๋ฆฌ๋ฉฐ ์„ ํƒ์ž์˜ ์ค‘์ฒฉ(Nesting)์ด๋‚˜ ์กฐ๊ฑด๋ฌธ, ๋ฐ˜๋ณต๋ฌธ, ๋‹ค์–‘ํ•œ ๋‹จ์œ„(Unit)์˜ ์—ฐ์‚ฐ ๋“ฑโ€ฆ ํ‘œ์ค€ CSS ๋ณด๋‹ค ํ›จ์”ฌ ๋งŽ์€ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด์„œ ํŽธ๋ฆฌํ•˜๊ฒŒ ์ž‘์„ฑํ• ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.

Sass์™€ SCSS๋Š” ์ฐจ์ด์ ์€?

๐Ÿณ๏ธ SCSS๋Š” CSS ๊ตฌ๋ฌธ๊ณผ ์™„์ „ํžˆ ํ˜ธํ™˜๋˜๋„๋ก ์ƒˆ๋กœ์šด ๊ตฌ๋ฌธ์„ ๋„์ž…ํ•ด ๋งŒ๋“  Sass์˜ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๋Š” CSS์˜ ์ƒ์œ„์ง‘ํ•ฉ(Superset) ์ด๋‹ค.๋˜ํ•œ Sass๋Š” ์„ ํƒ์ž์˜ ์œ ํšจ๋ฒ”์œ„๋ฅผ โ€˜๋“ค์—ฌ์“ฐ๊ธฐโ€™๋กœ ๊ตฌ๋ถ„ํ•˜๊ณ , SCSS๋Š” {}๋กœ ๋ฒ”์œ„๋ฅผ ๊ตฌ๋ถ„ํ•œ๋‹ค.


sass-data


SASS(Scss)์˜ ๋ฐ์ดํ„ฐํ˜•์‹



Nesting(์ค‘์ฒฉ)


 .bottom-bar-section {
    ul {
      list-style-type: none;
      margin: 0;
      padding-bottom: 20px;
      padding-left: 0;
    }
    li {
      padding-bottom: 5px;
    }
    p {
      margin-top: 40px;
    }
  }


์œ„์™€ ๊ฐ™์ด ์š”์†Œ๋ฅผ ๋ฌถ์–ด์ฃผ์–ด ์„ ํƒ์ž์˜ ๋ฐ˜๋ณต์„ ์ค„์—ฌ ๊ฐ€๋…์„ฑ์„ ๋†’์—ฌ์ฃผ๋ฉฐ ์ฝ”๋“œ๋ฅผ ์งง๊ฒŒ ํ•ด์ค€๋‹ค.



Ampersand (์ƒ์œ„ ์„ ํƒ์ž ์ฐธ์กฐ)

header {
    position: fixed;
    top: 0;
    z-index: 10000;
    width: 60%;
    margin-left: 20%;
    height: 60px;
    background-color: #f4f4f2;
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.05), 0 1px 0 rgba(144, 104, 104, 0.05);

    &:hover .nav li {
      opacity: 1;
      transition: all 0.5s;
    }

    &:not(:hover) .nav li {
      opacity: 0.3;
      transition: all 0.5s;
    }
}


Nesting ์•ˆ์—์„œ & ํ‚ค์›Œ๋“œ๋Š” ์ƒ์œ„(๋ถ€๋ชจ) ์„ ํƒ์ž๋ฅผ ์ฐธ์กฐํ•˜์—ฌ ์น˜ํ™˜ํ•จ



์†์„ฑ ์ค‘์ฒฉ

.box {
  font: {
    weight: bold;
    size: 10px;
    family: sans-serif;
  };
  margin: {
    top: 10px;
    left: 20px;
  };
  padding: {
    bottom: 40px;
    right: 30px;
  };
}


๊ฐ€๋…์„ฑ์„ ๋†’์—ฌ์ค€๋‹ค.



๋ณ€์ˆ˜(Variables)

$color-primary: #e96900;
$url-images: "/assets/images/";
$w: 200px;

.box {
  width: $w;
  margin-left: $w;
  background: $color-primary url($url-images + "bg.jpg");
}


์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ๊ฐ’ ๋ณ€์ˆ˜์ €์žฅ ๊ฐ€๋Šฅ



์—ฐ์‚ฐ๊ฐ€๋Šฅ

width: 50% - 20px;  // ๋‹จ์œ„ ๋ชจ์ˆœ ์—๋Ÿฌ(Incompatible units error)
width: calc(50% - 20px);  // ์—ฐ์‚ฐ ๊ฐ€๋Šฅ


์—ฐ์‚ฐ๊ฐ€๋Šฅ / ๋‚˜๋ˆ„๊ธฐ๋Š” ()๊ด„ํ˜ธ์— ๋„ฃ์–ด์ค˜์•ผํ•จ.



@mixin(์žฌํ™œ์šฉ)

@mixin ์ž‘๋ช… {
  font-size: 22px;
  font-weight: bold;
  font-family: sans-serif;
  color: orange;
}

h1 {
  @include ์ž‘๋ช…;
}


์•„์ฃผ ํ›Œ๋ฅญํ•œ๊ธฐ๋Šฅ. ์ฝ”๋“œ๋ฅผ ์ค„์—ฌ์ค€๋‹ค.



@if()

@if (์กฐ๊ฑด1) {
/_ ์กฐ๊ฑด1์ด ์ฐธ์ผ ๋•Œ ๊ตฌ๋ฌธ _/
} @else if (์กฐ๊ฑด2) {
/_ ์กฐ๊ฑด2๊ฐ€ ์ฐธ์ผ ๋•Œ ๊ตฌ๋ฌธ _/
} @else {
/_ ๋ชจ๋‘ ๊ฑฐ์ง“์ผ ๋•Œ ๊ตฌ๋ฌธ _/
}


js์˜ if์™€ ๊ฐ™์€๊ธฐ๋Šฅ



์ฐธ์กฐ https://heropy.blog/2018/01/31/sass/

์—…๋ฐ์ดํŠธ: