๐Ÿ”ฅFinal Project Day 3 - Grid Template

๐Ÿง™๐Ÿปโ€โ™‚๏ธgrid-template-columns, rows, ๊ทธ๋ฆฌ๊ณ  repeat()

html ์„ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ตฌ์„ฑํ–ˆ๋‹ค.

<body>
  <div class="grid">
    <div class="header"></div>
    <div class="content"></div>
    <div class="nav"></div>
    <div class="footer"></div>
  </div>
</body>

๊ทธ๋ฆฌ๊ณ  css ๋กœ ๋ถ€๋ชจ์š”์†Œ์— display ์†์„ฑ์„ grid ๋กœ ์ฃผ์—ˆ์œผ๋ฉฐ, ๊ฐ ํด๋ž˜์Šค๋งˆ๋‹ค ์ƒ‰์ƒ์„ ์ฃผ์—ˆ๋‹ค.

.grid {
  display: grid;
}

.header {
  background: #2ecc71;
}
.content {
  background: #3498db;
}
.nav {
  background: #8e44ad;
}
.footer {
  background: #f39c12;
}

์ด ์ƒํƒœ์—์„œ๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋ชจ์Šต์„ ํ™•์ธํ•  ์ˆ˜ ์—†๋‹ค.

๋ถ€๋ชจ ์š”์†Œ์ธ .grid ์— grid-template-column, grid-template-row ๋ฅผ ์ ์šฉํ•ด ์ฃผ์—ˆ๋‹ค.

grid-template-columns: 200px 200px 200px 200px;
grid-template-rows: 200px 200px 200px 200px;

columns 4 X rows 4 = 16 ๊ฐœ์˜ ๊ทธ๋ฆฌ๋“œ ํ…œํ”Œ๋ฆฟ์ด ๊ทธ๋ ค์ง„๋‹ค.

4by4

grid ๊ฐ€ ๊ฐ€์ง„ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ(repeat) ํ•ด์„œ ๋ฐ˜๋ณต ํ”ผํ•˜๊ธฐ

์œ„์ฒ˜๋Ÿผ ๋ฐ˜๋ณตํ•ด์„œ pixel ์„ ์ ๋Š” ๊ฒƒ๋ณด๋‹ค, grid ๊ฐ€ ๊ฐ€์ง„ ํ•จ์ˆ˜ repeat ์„ ์‚ฌ์šฉํ•˜๋ฉด ์‰ฝ๋‹ค!

์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€,

repeat(๋ฐ˜๋ณตํšŸ์ˆ˜, pixel ํฌ๊ธฐ) ์ด๋‹ค.

์•ž์„œ ์ž‘์„ฑํ–ˆ๋˜ ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ–ˆ๋‹ค. ๋˜‘๊ฐ™์ด ์ž‘๋™๋œ๋‹ค.

grid-template-columns: repeat(4, 200px);
grid-template-rows: repeat(4, 200px);

๐Ÿง™๐Ÿปโ€โ™‚๏ธGrid ๋งˆ๋ฒ•ํ•™๊ต 1ํ•™๋…„, grid-template-areas

grid-template-areas ๋Š” ์‰ฝ๊ฒŒ ์—‘์…€ ํ‘œ์ฒ˜๋Ÿผ ๋ ˆ์ด์•„์›ƒ์„ ๋””์ž์ธ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ์‰ฝ๋‹ค.

์ข€์ „์— columns 4 X rows 4 = 16 ๊ฐœ์˜ ๊ทธ๋ฆฌ๋“œ ํ…œํ”Œ๋ฆฟ์„ ๋งŒ๋“ค์—ˆ๋‹ค. 4 BY 4 ๋‹ค.

header ๊ฐ€ ๋งจ ์œ„์— ์žˆ๊ฒŒ ํ•˜๊ณ , content/nav ๊ฐ€ ๊ฐ™์ด ์žˆ์œผ๋ฉฐ ๋งจ ์•„๋ž˜์—๋Š” footer ๊ฐ€ ์žˆ๋„๋ก ์œ„์น˜์‹œ์ผœ ๋ณด์ž.

excel example

.grid {
  display: grid;
  grid-template-columns: repeat(4, 200px);
  grid-template-rows: repeat(4, 200px);
  grid-template-areas:
    'header header header header'
    'content content content nav'
    'content content content nav'
    'footer footer footer footer';
}

์œ„์˜ ์ฝ”๋“œ์ฒ˜๋Ÿผ grid-template-areas ์— ๊ณต๊ฐ„์„ ์ฐจ์ง€ํ–ˆ์œผ๋ฉด ํ•˜๋Š” ์†์„ฑ?(์ด๋ฆ„?) ์„ 4 BY 4 ๋กœ ์ ์–ด์ฃผ์—ˆ๋‹ค.

template ์„ ๋งŒ๋“ค์—ˆ์œผ๋ฉด ์ด์ œ ๊ฐ ํด๋ž˜์Šค์— grid-area ๋กœ ๋„ค์ž„ ์†์„ฑ์„ ์ค˜์•ผ ํ•œ๋‹ค.

.header {
  background: #2ecc71;
  grid-area: header;
}
.content {
  background: #3498db;
  grid-area: content;
}
.nav {
  background: #8e44ad;
  grid-area: nav;
}
.footer {
  background: #f39c12;
  grid-area: footer;
}

template area

์˜ค ์ •๋ง ํ…œํ”Œ๋ฆฟ ๋Œ€๋กœ ๋ ˆ์ด์•„์›ƒ์ด ๊ตฌ์„ฑ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

๋‹จ, grid-area ์— ์žˆ๋Š” ์ด๋ฆ„๊ณผ grid-template-areas ์— ์ง€์ •ํ•œ ์ด๋ฆ„์ด ๊ฐ™์•„์•ผ ํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๊ทธ๋ฆผ์„ ๋ณด๋ฉด ์˜ค๋ฅธ์ชฝ์— ํ•˜์–€ ๋นˆ ๊ณต๊ฐ„์ด ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์•„ ๋งŒ๋“  ๊ทธ๋ฆฌ๋“œ ๋ ˆ์ด์•„์›ƒ์ด ํ™”๋ฉด์— ๊ฝ‰ ์ฐจ ๋ณด์ด์ง€๋Š” ์•Š๋Š” ๋“ฏ ์‹ถ๋‹ค.

grid-template-columns: repeat(4, 200px); ๋Œ€์‹ ์—,

grid-template-columns: auto 200px; ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์•„๋ž˜ ๊ทธ๋ฆผ์ฒ˜๋Ÿผ ํ™”๋ฉด์— ๊ฝ‰ ์ฐจ๊ฒŒ ๋œ๋‹ค.

grid-template-columns: auto 200px;

full template area

๊ทธ๋ฆฌ๊ณ  ๊ธฐ์กด์— grid-template-rows ๋Š” 4 rows ๋ชจ๋‘ 200px ๋กœ ๋™์ผํ•˜๊ฒŒ ํ–ˆ์ง€๋งŒ,

ํ—ค๋” ๋ถ€๋ถ„๊ณผ ํ‘ธํ„ฐ ๋ถ€๋ถ„์€ 100px ๋กœ ํ•˜๋Š” ๋“ฑ์˜ ์ฐจ์ด๋ฅผ ์ฃผ๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์†์„ฑ์„ ์ ์šฉํ–ˆ๋‹ค.

repeat ๊ณผ px ๋“ค์„ ํ˜ผ์šฉํ•ด์„œ ์“ธ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค.

grid-template-rows: 100px repeat(2, 200px) 100px;

template area2

์•„ํ•˜ ํ™”๋ฉด ๊ตฌ์„ฑ (๋ ˆ์ด์•„์›ƒ) ์„ ์ด๋ ‡๊ฒŒ ์‰ฝ๊ฒŒ ์‰ฝ๊ฒŒ ๊ฐ€์ ธ๊ฐˆ ์ˆ˜ ์žˆ๊ตฌ๋‚˜!


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

GitHubMediumTwitterFacebook