๐งก INTRO
์์น์์ SCSS๋ฅผ ๋ฐฐ์ฐ๊ณ ์ค์ต ๋ฌธ์ ๋ฅผ ์งํํ๋๋ฐ SCSS์ ์ค์ฒฉ ๊ธฐ๋ฅ๋ง ์ฃผ๋ก ์ฌ์ฉํ๋ค๊ฐ ๋ค์ํ ๊ธฐ๋ฅ๋ค์ด ์๋ค๋ ๊ฒ์ ์๊ฒ ๋์ด ๊ธฐ๋กํฉ๋๋ค
๐ ๋ฌธ์ 

์ฒ์ ์์ฑํ ์ฝ๋
์ฒ์์ ์ฝ๋๋ฅผ ์์ฑํ์ ๋ ์ด๋ ๊ฒ ํ๋ฉด ๊ตณ์ด scss๋ฅผ ์ฌ์ฉํ ํ์๊ฐ ์๋? ์ถ์ ์ ๋๋ก ์ฝ๋๊ฐ ๊ธธ์์ต๋๋ค๐
@mixin box($size, $color) {
  width: $size;
  height: $size;
  background-color: $color;
}
.container {
  display: flex;
  .box1 {
    @include box(50px, red);
  }
  .box2 {
    @include box(100px, orange);
  }
  .box3 {
    @include box(150px, yellow);
  }
  .box4 {
    @include box(200px, green);
  }
  .box5 {
    @include box(250px, blue);
  }
  .box6 {
    @include box(300px, navy);
  }
  .box7 {
    @include box(350px, purple);
  }
}
๊ทธ๋ฅ ์ ์ถํ ๊น ์๊ฐํ์ง๋ง ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์์ ๊ฒ ๊ฐ์ scss์ ๊ธฐ๋ฅ์ ๋ํด ์ด๊ฒ ์ ๊ฒ ๊ฒ์ํด๋ณด๋ค๊ฐ scss์์ ๋ฐ๋ณต๋ฌธ์ ์ธ ์ ์๋ค๋ ์ฌ์ค์ ์๊ฒ ๋์๊ณ ์ด๋ฅผ ์ ์ฉํด ๋ณด์์ต๋๋ค!! ์ฌ๋ฌ ๋ฐ๋ณต๋ฌธ์ ์ธ ์ ์์๋๋ฐ ์ฒ์์ for ๋ฐ๋ณต๋ฌธ๊ณผ each ๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉ๋ฒ์ ์ฐพ์๋ณด๊ณ ๋์ ํผํฉํ์ฌ ์ฝ๋๋ฅผ ์์ฑํ์ต๋๋ค.
//for ๋ฐ๋ณต๋ฌธ๊ณผ each ๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉ๋ฒโ๏ธ 
//for ๋ฐ๋ณต๋ฌธ ์ฌ์ฉ ๋ฐฉ๋ฒ 
@for ๋ณ์ from (์์ ์ซ์) to (๋ ์ซ์){...}
//each ๋ฐ๋ณต๋ฌธ index ๊ฐ์ด ํ์ํ  ๊ฒฝ์ฐ ์ฌ์ฉ ์์
$fruits : (apple, banana, mango, orange);
.list_fruits {
    @each $fruit in $fruits {
        $i : index($fruits, $fruit);
        li:nth-child(#{$i}) {
            left: 100px * $i;
        }
    }
}
๋ ๋ฒ์งธ๋ก ์์ฑํ ์ฝ๋(๋ฐ๋ณต๋ฌธ ์ฌ์ฉ)
//๋๋ฒ ์งธ ์ฝ๋
$default-size: 50px;
$colors: (red, orange, yellow, green, blue, navy, purple);
@mixin boxs($num) {
	width: $default-size * $num;
	height: $default-size * $num;
}
.container {
	display: flex;
	@for $i from 1 to 8 {
		.box_#{$i} {
			@include boxs($i);
		}
	}
	@each $color in $colors {
		$i: index($colors, $color);
		.box_#{$i} {
			background: $color;
		}
	}
}
ํ์ง๋ง ์คํํด๋ณด๋ ํ๋ฉด์๋ ์ ๋จ๋๋ฐ ์๋์ฒ๋ผ ๋ฐ๋ณต๋ฌธ์ด ๋ ๋ฒ ๋์๊ฐ๊ณ ์์ด์ ์ ํ ํจ์จ์ ์ผ๋ก ๋ณด์ด์ง๊ฐ ์์์ต๋๋ค๐คฃ

์ต์ข ์ฝ๋
each ๋ฐ๋ณต๋ฌธ์์ index ๊ฐ์ ์ฐ๋๊น for๋ฌธ์ ๊ตณ์ด ๋๋ฆด ํ์๊ฐ ์์ ๊ฒ ๊ฐ์์ @include ๋ถ๋ถ์ ๋ฐ์ ๋ด๋ ค์คฌ์ต๋๋ค
//์ต์ข
 ์ฝ๋
$default-size: 50px;
$colors: (red, orange, yellow, green, blue, navy, purple);
@mixin boxs($num) {
	width: $default-size * $num;
	height: $default-size * $num;
}
.container {
	display: flex;
	@each $color in $colors {
		$i: index($colors, $color);
		.box_#{$i} {
			@include boxs($i);
			background: $color;
		}
	}
}
๊ทธ๋ฌ๋๋ ๋๋์ด ์ ๊ฐ ์ํ๋ ๋๋ก ์ปดํ์ผ ๋์์ต๋๋ค!!!๐

๐งก ๋ง๋ฌด๋ฆฌ
์ต๋ํ scss์ ์ฅ์ ์ ์ด๋ ค์ ์ฝ๋๋ฅผ ์ง๋ณด๊ณ ์ถ์ด์ ์ด๊ฒ ์ ๊ฒ ๊ฒ์ํด๋ณด๊ณ ๋ฐ๋ณต๋ฌธ๊น์ง ์จ ๋ดค๋๋ฐ ๊ฐ์ฅ ๋ฐ๋์งํ ์ฝ๋์ธ์ง๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง ์ฒ์ ์์ฑํ ์ฝ๋๋ณด๋ค๋ ๋งค์ฐ ์งง์์ ธ์ ๋ง์กฑํ๊ณ scss์ ๋ง์ ๊ธฐ๋ฅ์ด ์๋ค๋ ๊ฒ์ ์๊ฒ ๋์ด์ ํ์ํ ๋๋ง๋ค ์ฐพ์๋ณด๊ณ ์ ์ฉํด๋ณด๋ฉด ๋งค์ฐ ์ข์ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ ํ์ต๋๋ค!!
๐ ์ฐธ๊ณ
https://abcdqbbq.tistory.com/83
'์์นDT ๊ธฐ์ ์ฐ๊ณํ ํ๋ก ํธ์๋ ์ค๋ฌด ํ๋ก์ ํธ ๊ณผ์  7์ฃผ์ฐจ ๋ธ๋ก๊ทธ ํฌ์คํ '
'์์น' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [์์น ํ๋ก ํธ์๋] Styled-Components ๊ธฐ์ด ๋ฐฐ์ฐ๊ธฐ (0) | 2022.11.28 | 
|---|---|
| [์์น ํ๋ก ํธ์๋] React Router (0) | 2022.11.22 | 
| [์์น ํ๋ก ํธ์๋] ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๊ณ์ฐ๊ธฐ ๋ง๋ค๊ธฐ (1) | 2022.11.14 | 
| [์์น ํ๋ก ํธ์๋] for๋ฌธ๊ณผ while๋ฌธ์ ์ธ์  ์ฌ์ฉํด์ผ ํ ๊น? (0) | 2022.11.07 | 
| [์์น ํ๋ก ํธ์๋] HTML, CSS๋ก ํ์๊ฐ์ ์ฐฝ ๋ง๋ค์ด ๋ณด๊ธฐ (0) | 2022.10.30 | 
 
                  
                 
                  
                 
                  
                