๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ปSTUDY/CSS

[CSS] nth-child(n) / nth-child(-n)

๋ฐ˜์‘ํ˜•

css nth-child(n)์— ๋Œ€ํ•ด ํ™•์‹คํžˆ ์•Œ์•„๋ณด์ž.

/* 3,6,9.. ๋ฒˆ์งธ(3์˜๋ฐฐ์ˆ˜) ์ ์šฉ */
li:nth-child(3n) {}

/* 5๋ฒˆ์งธ ์ดํ›„ ๋ถ€ํ„ฐ ๋ชจ๋“  ๋ฆฌ์ŠคํŠธ ์ ์šฉ */
li:nth-child(n+5) {}

/* ์ฒซ๋ฒˆ์งธ๋ถ€ํ„ฐ 5๋ฒˆ์งธ๊นŒ์ง€ ์ ์šฉ */
li:nth-child(-n+5) {}

/* 5๋ฒˆ์งธ๋ถ€ํ„ฐ 10๋ฒˆ์งธ๊นŒ์ง€ ์ ์šฉ */
li:nth-child(n+5):nth-child(-n+10) {}

/* ๋์—์„œ 3๋ฒˆ์งธ๋งŒ ์ ์šฉ */
li:nth-last-child(3) {}

/* ํ™€์ˆ˜๋งŒ ์ ์šฉ */
li:nth-child(odd) {}

/* ์ง์ˆ˜๋งŒ ์ ์šฉ */
li:nth-child(even) {}

 

Reference

https://hohoya33.tistory.com/99

๋ฐ˜์‘ํ˜•