๐Ÿ”ฅFinal Project Day 4 - Grid Auto Columns and Rows

๐ŸฉAuto Columns and Rows

์ดˆ๊ธฐ css ์ฝ”๋“œ์ด๋‹ค.

.grid {
  display: grid;
  gap: 5px;
  height: 50vh;
  grid-template-columns: repeat(4, 100px);
  grid-template-rows: repeat(4, 100px);
}

.item:nth-child(odd) {
  background: #2ecc71;
}

.item:nth-child(even) {
  background: #3498db;
}

auto cols

item ๋“ค์ด 50๊ฐœ ์ผ ๋•Œ ์ปฌ๋Ÿผ์€ ๋งž์•„ ๋–จ์–ด์ง€์ง€๋งŒ rows ๋ฅผ 4๋กœ ์ง€์ •ํ•ด ์ฃผ์—ˆ๊ธฐ์—, 5๋ฒˆ์งธ row ๋ถ€ํ„ฐ๋Š” ์ €๋ ‡๊ฒŒ ๋†’์ด๊ฐ€ ์—†์ด ๋œฌ๋‹ค.

๊ทธ๋Ÿผ grid-template-rows: repeat(50, 100px) ํ•˜๋ฉด ๋˜๋Š”๊ฑฐ ์•„๋‹ˆ์•ผ?

๋˜๊ธฐ๋Š” ํ•˜์ง€๋งŒ ์ด๊ฑด ์ข‹์€ ํ•ด๊ฒฐ์ฑ…์ด ์•„๋‹ˆ๋‹ค.

์ด ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ํ•ด๊ฒฐ์ฑ…์œผ๋กœ grid-auto-rows ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋‹ค.

๐Ÿฉgrid-auto-rows

grid-template-rows ์— ์ง€์ •ํ•œ 4๊ฐœ์˜ row ๋ฅผ ๋„˜์–ด๊ฐ€๋ฉด ์ฆ‰ ๋” ๋งŽ์€ ์ปจํ…์ธ ๊ฐ€ ๋“ค์–ด๊ฐ€๋„, ๋”ฐ๋กœ rows ๋ฅผ ์ง€์ •ํ•ด์ฃผ์ง€ ์•Š์•„๋„,

๋””ํดํŠธ ๋ฐธ๋ฅ˜๋ฅผ ์ž๋™์œผ๋กœ ์ค˜์„œ row ๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ํ•  ๊ฒƒ์ด๋‹ค.

๊ธฐ๋ณธ ์ง€์ •ํ•œ 4๊ฐœ ์ด์™ธ์— ์ง€์ •ํ•˜์ง€ ์•Š์€ ๋” ๋งŽ์€ row ๋“ค๋„ ์ž๋™์ ์œผ๋กœ row ๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ๋‹ค.

grid-auto-rows: 100px;

๋‚ด๊ฐ€ ์„ค์ •ํ•œ row ๋ณด๋‹ค ๋” ๋งŽ์€ content ๊ฐ€ ์˜ค๊ฒŒ ๋  ๋•Œ (from server) grid-auto-rows ๊ฐ€ ์ž‘๋™ํ•  ๊ฒƒ์ด๋‹ค.

๊ธฐ๋ณธ์œผ๋กœ rows ๋ฅผ ์„ค์ •ํ•˜์ง€ ์•Š๊ณ  grid-auto-rows ๋งŒ ์ผ์„ ๋•Œ์—๋„ ์ž๋™์ ์œผ๋กœ ์ƒ์„ฑํ•˜๊ฒŒ ๋œ๋‹ค.

good

๐Ÿฉgrid-auto-flow ์™€ grid-auto-columns

์ƒˆ๋กœ์šด rows ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ ๋ง๊ณ  ์ƒˆ๋กœ์šด columns ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ํ• ๊นŒ?

grid-auto-flow ๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด์ž.

grid-auto-flow: column;

grid auto flow

์™€ ๋ฐฉํ–ฅ์ด ๋ฐ”๋€Œ์–ด ๋ฒ„๋ฆฐ๋‹ค. flow ๊ฐ€ ๋ฐ”๋€Œ์–ด ๋ฒ„๋ฆฐ๋‹ค. ์ด์ œ grid-auto-columns ๋ฅผ ์จ๋ณด์ž.

grid-auto-columns: 100px;

grid auto cols


Written by@[DotoriMook]
ํ”„๋ก ํŠธ์—”๋“œ ์ฃผ๋‹ˆ์–ด ๊ฐœ๋ฐœ์ž ๋„ํ† ๋ฆฌ๋ฌต์˜ ๊ธฐ์ˆ ๊ฐœ๋ฐœ ๋ธ”๋กœ๊ทธ ์ž…๋‹ˆ๋‹ค.

GitHubMediumTwitterFacebook