SCSS -1

hb-developerΒ·2021λ…„ 4μ›” 20일
0

SCSS

λͺ©λ‘ 보기
1/2

SCSS πŸ˜€

SCSS λŠ” CSS λ₯Ό 쒀더 μ‰½κ²Œ μž‘μ„±μ‹œμΌœμ£ΌλŠ” μ „μ²˜λ¦¬κΈ°(Compiler) μž…λ‹ˆλ‹€.

κ°€μž₯ λˆˆμ— λ›°λŠ” 이점은 쀑첩을 κ°„μ†Œν™” μ‹œμΌœμ€λ‹ˆλ‹€.

.conatiner {

}
.conatiner .inner{

}

.conatiner .inner .menu {

}

.conatiner .inner .menu .main-menu{

}

CSSλŠ” ν•˜μœ„ μš”μ†Œλ₯Ό λŠ˜λ¦΄λ•Œλ§ˆλ‹€ μƒμœ„ μš”μ†Œλ₯Ό μ „λΆ€ μ μ–΄μ€˜μ•Ό ν•©λ‹ˆλ‹€.
ν•˜μ§€λ§Œ SCSS λŠ” ν”„λ‘œκ·Έλž˜λ° μ–Έμ–΄ 처럼 쀑첩을 μ§€μ›ν•©λ‹ˆλ‹€.

.conatiner{
  .inner{
    .menu{
      .main-menu{
        
      }
    }
  }
}

μ„ νƒμž

μžμ‹μ„ νƒμž
> κΊ½μ‡  기호λ₯Ό μ¨μ€λ‹ˆλ‹€.

.conatiner{                        //.conatiner > .inner { }
  >.inner{}}

μΌμΉ˜μ„ νƒμž
& μ— νΌμ„Όλ“œ 기호λ₯Ό μ¨μ€λ‹ˆλ‹€.

//scss
.list {
  li {
    &:last-child {
      margin-right: 0;
    }
  }
}
.list li:last-child {
  margin-right: 0;
}

ν˜Ήμ€ μƒμœ„ μ„ νƒμžλ₯Ό μ°Έμ‘° ν• μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

.fs {
  &-small { font-size: 12px; }
  &-medium { font-size: 14px; }
  &-large { font-size: 16px; }
}
.fs-small {
  font-size: 12px;
}
.fs-medium {
  font-size: 14px;
}
.fs-large {
  font-size: 16px;
}

쀑첩속성

margin : {}; λŠ” margin- 둜 λ°”λ€λ‹ˆλ‹€

body {
  margin:{
    top:20px;
    right: 30px;
    bottom: 40px;
    left: 10px;
  };
}
body {
  margin-top: 20px;
  margin-right: 30px;
  margin-bottom: 40px;
  margin-left: 10px;
}

λ³€μˆ˜

SCSS μ—μ„œλŠ” λ³€μˆ˜λ₯Ό μ„ μ–Έν•˜κ³  μ§€μ •ν• μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.

body {
 top:100px;
 .item{
   width:100px;
   height: 100px;
 } 
}

$ λ‹¬λŸ¬ μ‚¬μΈμœΌλ‘œ size:100px; λ₯Ό μ„ μ–Έν•˜κ³  $size λ₯Ό μž…λ ₯ν•˜λ©΄ λ™μΌν•˜κ²Œ 좜λ ₯λ©λ‹ˆλ‹€.

$size:100px;
body {
 top:$size;
 .item{
   width:$size;
   height: $size;
 } 
}

λ‹€λ§Œ μ„ μ–Έλœ 곳에 따라 λ³€μˆ˜μ‚¬μš©μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€.
블둝 μ•ˆμ— μ„ μ–Έλ˜λ©΄ κ·Έ λΈ”λ‘μ—μ„œλ§Œ, μ „μ—­ κ³΅κ°„μ—μ„œ μ„ μ–Έλ˜λ©΄ css μ „μ²΄μ—μ„œ μ‚¬μš©μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€.

μ‚°μˆ μ—°μ‚°

μ•„λž˜ μ‚°μˆ μ—°μ‚°μ„ ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.

SCSS
box {
 width: 50px + 20px;
 height: 40px - 20px;
 margin-top: 50px*2;
 margin-bottom: 40px / 2;
 margin-left: 20px % 6 ;
}
CSS
box {
  width: 70px;
  height: 20px;
  margin-top: 100px;
  margin-bottom: 40px/2;      // κ³„μ‚°μ•ˆλ¨
  margin-left: 2px;
}

λ‹€λ§Œ λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€.

css μ—μ„œλŠ” / 기호λ₯Ό 단좕 기호둜 인식 ν•˜κΈ° λ•Œλ¬Έμ— μ•„λž˜μ™€ 같은 방법을 μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.

1. λ³€μˆ˜ μ„ μ–Έν•˜κΈ° λ³€μˆ˜λ₯Ό μ„ μ–Έν•˜κ³  λ‚˜λˆ„κΈ° 기호λ₯Ό μ‚¬μš©ν•œλ‹€. ex) $size / 2
2.κ΄„ν˜Έλ₯Ό μ‚¬μš©ν•œλ‹€ (40px / 2) == 20px

! μ‚°μˆ μ—°μ‚°μ€ 같은 λ‹¨μœ„λΌλ¦¬ κ³„μ‚°ν•΄μ•Όν•©λ‹ˆλ‹€.
λ§Œμ•½ λ‹€λ₯Έ λ‹¨μœ„ 끼리 κ³„μ‚°ν•˜λ €λ©΄ calc() ν•¨μˆ˜λ₯Ό μ΄μš©ν•΄μ•Όν•©λ‹ˆλ‹€.

@mixin @include

@mixin 을 μ΄μš©ν•˜λ©΄ μ†μ„±κ°’μ˜ λͺ¨μŒμ„ λ³€μˆ˜μ²˜λŸΌ μ‚¬μš©ν• μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.

SCSS
@mixin size {           // size μ„ μ–Έ
  height: 100px;
  width: 100px;
  color:green
}

.container{
  @include size;            //size λŒ€μž…
  .item{
    @include size;
  }
}
CSS
.container {
  height: 100px;
  width: 100px;
  color: green;
}
.container .item {
  height: 100px;
  width: 100px;
  color: green;
}

λ§Œμ•½ .container λŠ” 100px 으둜 item은 50px 둜 λ°”κΎΈλ €λ©΄ μ–΄λ–»κ²Œ ν•΄μ•Όν• κΉŒμš”?
@mixin λŠ” μ„ μ–Έν• λ•Œ 인수λ₯Ό λ°›μ„μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.

SCSS
@mixin size($sz) {
  height: $sz;
  width: $sz;
  color:green;
}

.container{
  @include size(100);
  .item{
    @include size(50);
  }
}
.container {
  height: 100;
  width: 100;
  color: green;
}
.container .item {
  height: 50;
  width: 50;
  color: green;
}

λ§Œμ•½ 일일히 μΈμˆ˜κ°’μ„ λŒ€μž…ν•˜λŠ”κ²Œ λ²ˆκ±°λ‘œμšΈλ•ŒλŠ” λ§€κ°œλ³€μˆ˜μ— 기본값을 μ„€μ •ν•΄μ€„μˆ˜ μžˆμŠ΅λ‹ˆλ‹€. @mixin size($sz:100px) κΈ°λ³Έκ°’ κ·ΈλŒ€λ‘œ μ‚¬μš©ν•˜κ³ μ‹Άμ„λ–ˆ @include size κ·ΈλŒ€λ‘œ μ‚¬μš©ν• μˆ˜ 있죠둜 μ‚¬μš©ν• μˆ˜ 있죠

참고자료 : https://heropy.blog/2018/01/31/sass/

profile
배우면 바뀐닀

0개의 λŒ“κΈ€