for๋ฌธ ์ฌ์ฉ์ SCSS์์ ์ฌ์ฉ ํ ์ ์๋ค๋ ์ฌ์ค์ ์ฒ์ ์์์๋ 'ํ ๊ธ์ฟค...' ํ๊ณ ๊ฐ๋งํ ๋ณด๋ค๊ฐ ์ ์ ํ ์ฌ์ฉ๋ฐฉ๋ฒ์ด ๋ ์ฌ๋๊ณ ... ๊ทธ ์๊ฐ ๋จธ๋ฆฌ์์ ์ข ์ด์ณค๋ค... ์ ๋ ์นด....!!๐
for (let i = 0; i < 10; i++) {
console.log(`nth-child(${i})`);
}
@for $i from 1 through 10 {
div:nth-child(#{$i}) {
width: 100px * $i
}
}
@for
๋ก for๋ฌธ์ ์คํ ํ ๋ค $i
๋ก ๋ณ์๋ช
์ ์ง์ ํ๋ค. JS์ ๊ฐ์ด ํต์์ ์ผ๋ก i
๋ฅผ ์ฌ์ฉํ๋ ๋ฏ ํ๋ค!
from 1 through 10
1๋ถํฐ 10๊น์ง 10๋ฒ ๋ฐ๋ณตํ๋ค. ๊ฐ ์ซ์๋ i
์ ํ ๋น๋๋ค
์ค๊ดํธ({ }
)๋ด์์ ์์(ํ๊ทธ)๋ฅผ ์ ํํ๊ณ , ๋๊ฐ์ด ์์ฑ๊ณผ ์์ฑ๊ฐ์ ์ ์ฉํ๋ฉด ๋๋ค
์์(ํ๊ทธ)๋ช
์์ ๋ณ์๋ฅผ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด #{ }
๋ณด๊ฐ๋ฒ์ ์ฌ์ฉํ๋ค
ex) div:nth-child(#{$i})
์์ฑ๊ฐ์ผ๋ก ๋ณ์๋ฅผ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด ๋ณด๊ฐ๋ฒ์์ด ๋ฐ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ๋ค
ex) { width: 100px * $i }
๊ฐ์ฅ ์ต์ํ JS์ for๋ฌธ๊ณผ ๋น๊ตํด๋ณด์๋ฉด ์ผ์ถ ๋น์ทํ์ง๋ง ๋ช๊ฐ์ง ์ฐจ์ด์ ์ ๋ณด์ธ๋ค
Zero-Based-Numbering : JS์์๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๋ก๋ฒ ์ด์ค๋ก ์ซ์๋ฅผ ์นด์ดํ
ํ์ง๋ง CSS์์๋ ์ ์ฉ๋์ง ์๋๋ค. from 1 through 10
๋ ๋ณด์ด๋ ๊ทธ๋๋ก 1๋ถํฐ 10๊น์ง 10๋ฒ์ ๋ฐ๋ณตํ๋ค
๋ณด๊ฐ๋ฒ : JS์์์ ๋ณด๊ฐ๋ฒ์ ` `(๋ฐฑํฑ๊ธฐํธ)์์์ ${ }
์ ๋ชจ์์ผ๋ก ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
SCSS์์๋ ๋ฐ๋ก #{ }
๋ก ์ฌ์ฉํ๋ฉด ๋๋ค. SCSS์์ ๋ณ์๋ฅผ $๋ฌ๋ฌ์ฌ์ธ์ผ๋ก ์์ฑํ๋ ํท๊ฐ๋ฆฌ์ง ์๊ฒ ์ฌ์ฉ๋ฒ์ ๋ฐ๊พผ ๋ฏ ํ๋ค.
์ด๊ฑด ์ค์ ๋ก ๋ด๊ฐ ๋ง๋ ํ์ด์ง์ ์ผ๋ถ์ธ๋ฐ(Artboxํด๋ก ) ์ด๋ ๊ฒ ๊ฐ๊ฐ์ ์์๋ณ ๋ธ๋ก์ ๊ฐ๊ธฐ ๋ค๋ฅธ ์ด๋ฏธ์ง๊ฐ ๋ค์ด๊ฐ๋ ํํ์ด๋ค. ์ฌ์ง์ด ๋ง์ฐ์ค๋ฅผ hoverํ๋ฉด ๋ ๋ค๋ฅธ ์ด๋ฏธ์ง๊ฐ ๋ค์ด๊ฐ์ผ ํ๋ค.. (๊ฐ๋
ธ๊ฐ๋ค..)
์๋๋ ์ค์ ๋ก ๋ด๊ฐ ์ ์ฉํ ์ฝ๋
&:nth-child(1)>a{background-image: url(./../images/best_item1.jpg);}
&:nth-child(2)>a{background-image: url(./../images/best_item2.jpg);}
&:nth-child(3)>a{background-image: url(./../images/best_item3.jpg);}
&:nth-child(4)>a{background-image: url(./../images/best_item4.jpg);}
&:nth-child(5)>a{background-image: url(./../images/best_item5.jpg);}
&:nth-child(6)>a{background-image: url(./../images/best_item6.jpg);}
&:nth-child(7)>a{background-image: url(./../images/best_item7.jpg);}
&:nth-child(8)>a{background-image: url(./../images/best_item8.jpg);}
&:nth-child(9)>a{background-image: url(./../images/best_item9.jpg);}
&:nth-child(10)>a{background-image: url(./../images/best_item10.jpg);}
&:nth-child(1)>a:hover{background-image: url(./../images/best_item_back1.jpg);}
&:nth-child(2)>a:hover{background-image: url(./../images/best_item_back2.jpg);}
&:nth-child(3)>a:hover{background-image: url(./../images/best_item_back3.jpg);}
&:nth-child(4)>a:hover{background-image: url(./../images/best_item_back4.jpg);}
&:nth-child(5)>a:hover{background-image: url(./../images/best_item_back5.jpg);}
&:nth-child(6)>a:hover{background-image: url(./../images/best_item_back6.jpg);}
&:nth-child(7)>a:hover{background-image: url(./../images/best_item_back7.jpg);}
&:nth-child(8)>a:hover{background-image: url(./../images/best_item_back8.jpg);}
&:nth-child(9)>a:hover{background-image: url(./../images/best_item_back9.jpg);}
&:nth-child(10)>a:hover{background-image: url(./../images/best_item_back10.jpg);}
10๊ฐ์ ๋ธ๋ญ์ ๊ฐ๊ฐ ๋ค๋ฅธ ์ด๋ฏธ์ง๋ฅผ ์ ์ฉํ๊ณ , hoverํ์ ๋ ๋ ๋ค๋ฅธ 10๊ฐ์ ์์ดํ
์ ๋ค์ ์ ์ฉํ๋ค...ใ
ใ
ใ
ใ
ใ
ใ
(๐คฏ) ๋๋ฆ ์์
์ ์ฝ๊ฒ ํ๋ ค๊ณ ์ด๋ฏธ์ง์ ์ด๋ฆ์ ํต์ผํ๊ณ ์ซ์๋ง ๋ค๋ฅด๊ฒ ์ ์ฉํ๋๋ฐ ํด๋ณธ ์ฌ๋๋ค์ ์๊ฒ ์ง๋ง ํ๋ํ๋ ์ซ์ ๋ฐ๊ฟ์ ๋ค๋๊ฒ๋ ์๋นํ ๊ท์ฐฎ์ ๋
ธ๊ฐ๋ค ์์
์ด์๋ค
ํ ์ค ๋น nth-child
์ ์ซ์๋ ๋ฐ๊พธ๊ณ , ์ด๋ฏธ์ง ๊ฒฝ๋ก์ ์ซ์๋ ๋ฐ๊พธ๊ณ ๊ทธ๊ฒ ์ด 20์ค.. ์ด 40๊ฐ์ ์ซ์๋ฅผ ๋ฐ๊ฟ์ค์ผํ๋ค
@for $i from 1 through 10 {
&:nth-child(#{$i})>a{background-image: url(./../images/best_item#{$i}.jpg);}
&:nth-child(#{$i})>a:hover{background-image: url(./../images/best_item_back#{$i}.jpg);}
}
ใ ใ ใ ใ ์ง์ง... ํด๋ก ํ์ด์ง ์์ ํ ๋๋ง๋ค ์ ๋ฐ์์ ์์ ์ ๋ฐ๋์ ๊ฑฐ์ณ์ผํ๋ ๋ ์ด์์์ด ๊ผญ ํ๋ฒ์ฉ์ ์์๋๋ฐ SCSS๋ฅผ ๊ณ์ ์ฌ์ฉํด์์ผ๋ฉด์ ์ด๋ ๊ฒ๋ ํ ์ ์๋ค๋ ๊ฑธ ์ด์ ์์ผ ์๊ฒ ๋๊ฒ ์์ฃผ ์ํตํ๋ค..!!!
์์ผ๋ก ๋จ์๋ฐ๋ณต ๋ ธ๊ฐ๋ค๊ฐ ๋๋ ต์ง ์๊ฒ ๋ ์ง๋..!?