๐Ÿ‘ Gird-box

๋ฐ•์ƒ์€ยท2021๋…„ 11์›” 15์ผ
0

๐Ÿช„ CSS ๐Ÿช„

๋ชฉ๋ก ๋ณด๊ธฐ
6/6
post-thumbnail

1. Grid

Flex์™€ ๋‹ค๋ฅด๊ฒŒ ๋‘ ๋ฐฉํ–ฅ ๋ ˆ์ด์•„์›ƒ ์‹œ์Šคํ…œ์ด๋‹ค.

2. Grid Container

display: grid;๋ฅผ ์„ ์–ธํ•œ ํƒœ๊ทธ๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

3. Grid Item

Grid Container์˜ ์ž์‹ ํƒœ๊ทธ๋“ค์„ ์˜๋ฏธํ•œ๋‹ค.

4. grid-template-*

Grid Container์—์„œ ์ •์˜ํ•ด์ฃผ๋ฉฐ Grid Track์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•ด์ฃผ๋Š” ์†์„ฑ์ด๋‹ค.
์ฆ‰, Grid Item์˜ ํฌ๊ธฐ๋ฅผ ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

  • grid-template-columns๋Š” ๊ทธ๋ฆฌ๋“œ ์•„์ดํ…œ์˜ ๊ฐ€๋กœ๋ฐฉํ–ฅ ๋ฐฐ์น˜๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค.
  • grid-template-rows๋Š” ๊ทธ๋ฆฌ๋“œ ์•„์ดํ…œ์˜ ์„ธ๋กœ๋ฐฉํ–ฅ ๋ฐฐ์น˜๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค.
.grid-container {
	display: grid;
    /* ๊ฐ€๋กœ๋กœ 3๊ฐœ 200px, 500px, 300px ์˜์—ญ๋งŒํผ ์ฐจ์ง€ํ•˜๋„๋ก ๋ฐฐ์น˜ */
    grid-template-columns: 200px 500px 300px;
    
    /* ๊ฐ€๋กœ๋กœ 3๊ฐœ ๊ฐ™์€ ์˜์—ญ๋งŒํผ ๋‚˜๋ˆ ์„œ ๋ฐฐ์น˜ ( ์•„๋ž˜ ๋‘ ๊ฐœ๋Š” ์™„๋ฒฝํžˆ ๋™์ผ ) */
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-columns: repeat(3, 1fr);
    
    /* ๊ฐ€๋กœ๋กœ 3๊ฐœ ์ตœ์†Œ 100px, ์ตœ๋Œ€ auto ๋ฐฐ์น˜ */
    grid-template-columns: repeat(3, minmax(100px, auto));
}

๊ทธ๋ฆฌ๋“œ ์ปจํ…Œ์ด๋„ˆ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ฐ€๋กœ๋“  ์„ธ๋กœ๋“  ๊ทธ๋ฆฌ๋“œ ์•„์ดํ…œ์„ ๊ฐ€๋“ ์ฑ„์šด๋‹ค.( = ์œ ์—ฐํ•˜๊ฒŒ ๋Š˜๋ฆฐ๋‹ค. )

5. auto-fill๊ณผ auto-fit

repeat()์— ์‚ฌ์šฉํ•˜๋ฉฐ ๋ฐ˜๋ณตํ•  ํšŸ์ˆ˜๋ฅผ ๋ฏธ๋ฆฌ ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  ํฌ๊ธฐ์— ๋งž๊ฒŒ ๋ฐ˜๋ณตํ•˜๊ฒŒ ํ•ด์ฃผ๋Š” ๊ฐ’์ด๋‹ค.
auto-fill์€ ๋‚จ์€ columns๋ฅผ ์ฑ„์šฐ์ง€ ์•Š๊ณ  ๋‚จ๊ฒจ๋‘๋Š” ๋ฐ˜๋ฉด
auto-fit์€ ๊ฐ™์€ ๋ผ์ธ์˜ Grid Item์„ ๋ฐฐ์น˜ํ•˜๊ณ  ๋‚จ์€ ๊ณต๊ฐ„์„ ๊ฐ™์€ ๋น„์œจ๋กœ ๋‚˜๋ˆ ๊ฐ€์ง„๋‹ค.

.grid-container {
	display: grid;
    /* ๊ฐ€๋กœ์— ๊ทธ๋ฆฌ๋“œ ์•„์ดํ…œ์ด 200px์ด ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๋งŒํผ๋งŒ ์ฑ„์›€ */
	grid-template-columns: repeat(auto-fill, minmax(200px, auto));
    
    /* ๊ฐ€๋กœ์— ๊ทธ๋ฆฌ๋“œ ์•„์ดํ…œ์ด 20%๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๋งŒํผ๋งŒ ์ฑ„์›€ */
    /* ์ฆ‰, ๊ฐ€๋กœ์— 5๊ฐœ์”ฉ ๋“ค์–ด๊ฐ€๋ฉด์„œ ํฌ๊ธฐ๋Š” ๋™์ผํ•œ ๋น„์œจ๋กœ ๋‚˜๋ˆ ๊ฐ€์ง */
	grid-template-columns: repeat(auto-fill, minmax(20%, auto));
}

6. gap

row-gap, column-gap, gap์ด ์กด์žฌํ•œ๋‹ค.

7. grid-auto-columns๊ณผ grid-auto-rows

ํ†ต์ œ๋ฅผ ๋ฒ—์–ด๋‚œ Grid Track์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•ด์ฃผ๋Š” ์†์„ฑ์ด๋‹ค.

.grid-container {
	display: grid;
    /* ์ด 3๊ฐœ์˜ ๋ผ์ธ์„ ๊ฐ™์€ ํฌ๊ธฐ๋กœ ๋ฐฐ์น˜ํ•จ */
    /* 3์ค„ ์ดˆ๊ณผ์ผ ๊ฒฝ์šฐ ์ฆ‰, 4๋ฒˆ์งธ ๋ผ์ธ๋ถ€ํ„ฐ๋Š” "ํ†ต์ œ๋ฅผ ๋ฒ—์–ด๋‚œ"๋ผ์ธ์ด ๋˜๊ณ , ํฌ๊ธฐ๊ฐ€ auto๊ฐ’์ด ๋œ๋‹ค. */
    grid-template-rows: repeat(3, 1fr);
    
    /* ์ฃผ์–ด์ง„ ๋ชจ๋“  ๋ผ์ธ์„ ์ •ํ•ด์ง„ ํฌ๊ธฐ๋กœ ๋ฐฐ์น˜ํ•จ */
    grid-auto-rows: 300px;
    grid-auto-rows: 1fr;
    grid-auto-rows: minmax(100px, auto);
}

ํ†ต์ œ๋ฅผ ๋ฒ—์–ด๋‚œ์ด๋ž€ grid-template-*์„ ์ ์šฉํ•˜์ง€ ์•Š์€ ๊ทธ๋ฆฌ๋“œ ์•„์ดํ…œ์„ ๋งํ•œ๋‹ค.

8. grid-column์™€ grid-row

๊ทธ๋ฆฌ๋“œ ์•„์ดํ…œ์ด ์ฐจ์ง€ํ•  ์˜์—ญ์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ์ด๋‹ค.

.grid-container {
	display: grid;
    grid-template-rows: repeat(3, 1fr);
}
.grid-item:nth-child(1) {
	/* ์•„๋ž˜ 3๊ฐ€์ง€๋Š” ๋ชจ๋‘ ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ */
	grid-column-start: 1;
	grid-column-end: 3;
    grid-row-start: 1;
	grid-row-end: 3;
    
    grid-column: 1 / 3;
    grid-row: 1 / 3;
    
    grid-column: 1 / span 2;
    grid-row: 1 / span 2;
    
    /* ๋ณธ๋ž˜ ์œ„์น˜์—์„œ ์‹œ์ž‘ํ•œ๋‹ค๋ฉด ์‹œ์ž‘์  auto๋กœ ๋Œ€์ฒด ๊ฐ€๋Šฅ */
    grid-row: auto / span 2;
}

9. grid-auto-flow

Grid Item์˜ ๋ฐฐ์น˜ ์ˆœ์„œ๋‚˜ ๋นˆ์นธ์„ ์ฑ„์›Œ๋„ฃ์„์ง€๋ฅผ ์ง€์ •ํ•œ๋‹ค.
row, column, dense, row dence, column dence๊ฐ€ ์กด์žฌํ•œ๋‹ค.

10. *-items

Grid Item๋“ค์˜ ๋ฐฐ์น˜๋ฅผ ์ •ํ•œ๋‹ค.
justify-items(๊ฐ€๋กœ๋ฐฉํ–ฅ), align-items(์„ธ๋กœ๋ฐฉํ–ฅ), place-items๊ฐ€ ์กด์žฌํ•œ๋‹ค.

11. *-content

Grid Item๋“ค ์ „์ฒด๋ฅผ ํ•œ๋ฒˆ์— ๋ฐฐ์น˜ํ•œ๋‹ค.
justify-content(๊ฐ€๋กœ๋ฐฉํ–ฅ), align-content(์„ธ๋กœ๋ฐฉํ–ฅ), place-content๊ฐ€ ์กด์žฌํ•œ๋‹ค.

12. *-self

Grid Item ๊ฐ๊ฐ์„ ๊ฐ ๊ณต๊ฐ„์—์„œ์˜ ๋ฐฐ์น˜๋ฅผ ์ง€์ •ํ•œ๋‹ค.
justify-self, align-self, place-self๊ฐ€ ์กด์žฌํ•œ๋‹ค.

0. ์šฉ์–ด์ •๋ฆฌ

  • Grid Track: Grid์˜ rows์™€ column์„ ์˜๋ฏธ
  • fr: ๋น„์œจ์„ ์˜๋ฏธ
  • repeat(): ๋ฐ˜๋ณต์„ ์˜๋ฏธ => repeat(4, 1fr)
  • minmax(): ์ตœ์†Œ, ์ตœ๋Œ€๊ฐ’ ์ง€์ • => minmax(100px, auto)

์ฐธ๊ณ ํ•œ ์‚ฌ์ดํŠธ

0๊ฐœ์˜ ๋Œ“๊ธ€