[css] flex vs grid


flex vs grid

  • flex๋Š”ย 1์ฐจ์›์ ์ธ ๊ตฌ์กฐ
    row ํ˜น์€ column ์ค‘ ํƒ1 ํ•˜์—ฌ ๋ฐฐ์น˜ ๋ฐฉํ–ฅ์„ ๊ฒฐ์ •

  • grid๋Š”ย 2์ฐจ์›์ ์ธ ๊ตฌ์กฐ
    row์™€ column ๋ฐฉํ–ฅ์˜ ๋ฐฐ์น˜ ๋ฐฉ์‹์„ ๋™์‹œ์— ์„ค์ •



flex ์†์„ฑ

๏ฟผ flex-direction: ์ปจํ…Œ์ด๋„ˆ ๋‚ด์˜ ์•„์ดํ…œ์„ ๋ฐฐ์น˜ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ฃผ์ถ• ๋ฐ ๋ฐฉํ–ฅ(์ •๋ฐฉํ–ฅ, ์—ญ๋ฐฉํ–ฅ)์„ ์ง€์ •

justify-content: ์ฃผ์ธก ๊ธฐ์ค€์œผ๋กœ ์š”์†Œ๋“ค์˜ ์œ„์น˜ ์ง€์ •

align-items: ๊ต์ฐจ์ถ• ๊ธฐ์ค€์œผ๋กœ ์š”์†Œ๋“ค์˜ ์œ„์น˜ ์ง€์ •

flex-wrap: ์š”์†Œ๋“ค์ด ๊ฐ•์ œ๋กœ ํ•œ์ค„์— ๋ฐฐ์น˜๋˜๊ฒŒ ํ•  ๊ฒƒ์ธ์ง€, ๋˜๋Š” ์—ฌ๋Ÿฌํ–‰์œผ๋กœ ๋‚˜๋ˆ„์–ด ํ‘œํ˜„ ํ•  ๊ฒƒ์ธ์ง€ ๊ฒฐ์ •ํ•˜๋Š” ์†์„ฑ

align-content: flex wrap์ผ ๊ฒฝ์šฐ, ๊ต์ฐจ์ถ•์„ ๊ธฐ์ค€์œผ๋กœ ์š”์†Œ๋“ค์˜ ์œ„์น˜์™€ ์ฃผ์œ„ ๋นˆ ๊ณต๊ฐ„์„ ๋ฐฐ์น˜

display: flex
flex-direction: row | row-reverse | column | column-reverse
justify-content: flex-star | flex-end | center | space-between | space-around | space-evenly
align-items: stretch | flex-start | flex-end | center
flex-wrap: nowrap | wrap | wrap-reverse
align-content: stretch | flex-start | flex-end | center | space-between | space-around 
 


grid ์†์„ฑ

grid-container: grid๊ฐ€ ์ ์šฉ๋œ ์š”์†Œ

grid-item: grid๊ฐ€ ์ ์šฉ๋œ ์š”์†Œ์˜ ์ž์‹ ์š”์†Œ๋“ค

grid-line: grid-item ์‚ฌ์ด์˜ ๊ฒฝ๊ณ„๋ฅผ ์˜๋ฏธ

grid-number: ํ•ด๋‹น grid-line์ด ๋ช‡๋ฒˆ์งธ line์ธ์ง€๋ฅผ ์˜๋ฏธ

grid-template: grid์˜ ํ–‰&์—ด์˜ ๊ฐœ์ˆ˜ ๋ฐ ํฌ๊ธฐ๋ฅผ ์ง€์ •

grid-template-rows: row๋Š” ํ–‰์˜ ํ…œํ”Œ๋ฆฟ ์ง€์ •

grid-template-columns: columns๋Š” ์—ด์˜ ํ…œํ”Œ๋ฆฟ์„ ์ง€์ •

grid-column & grid-row: grid-number์˜ ์‹œ์ž‘์  / ์ข…๋ฃŒ์ , ๊ฐ๊ฐ์˜ย grid-item์ด ์—ด๊ณผ ํ–‰ ๋ฐฉํ–ฅ์œผ๋กœ ์–ผ๋งˆ๋งŒํผ์˜ ์˜์—ญ์„ ์ฐจ์ง€ํ•  ์ง€ ์ •์˜

display: grid
grid-template-columns: repeat(4, 1fr)
grid-column: 1 / 4

* fr: fraction(๋ถ„์ˆ˜)์˜ ์•ฝ์ž๋กœ grid-template์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋น„์œจ ๋‹จ์œ„.
* repeat(): grid-template์— repeat(a, b)๋ผ๊ณ  ์ž…๋ ฅํ•˜๋ฉด,ย b๊ทœ๊ฒฉ์˜ grid-template์„ a๊ฐœ ์ƒ์„ฑํ•œ๋‹ค๋Š” ์˜๋ฏธ.






ยฉ 2023. by MyeongheeJung

Powered by MH.J