๐Ÿ”ฅFinal Project Day 4 - Grid Place Content, align-self, justify-self

๐ŸŒตPlace Content on Grid

items ๋Š” cell ์ค‘์— ํ•˜๋‚˜์ด๋ฉฐ, ๊ฐ ๊ฐ ๊ฐœ๋ณ„์ ์œผ๋กœ ํ•˜๋‚˜ ํ•˜๋‚˜๋ฅผ ์˜๋ฏธํžŒ๋””.

ํ•˜์ง€๋งŒ content ๋Š” ์ „์ฒด ๊ทธ๋ฆฌ๋“œ ์ด๋‹ค.

์ „์ฒด Grid ์˜ ์ปจํ…์ธ ๋ฅผ ์ •๋ ฌํ•˜๋Ÿฌ ๋– ๋‚˜๋ณด์ž.

.grid {
  display: grid;
  background: black;
  gap: 10px;
  height: 250vh;
  grid-template-columns: repeat(4, 100px);
  grid-template-rows: repeat(4, 100px);

  /* ์—ฌ๊ธฐ ์•„๋ž˜์— ์ž‘์„ฑ ์˜ˆ์ •  */
}

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

๐ŸŒต์ „์ฒด ๊ทธ๋ฆฌ๋“œ๋ฅผ ์ˆ˜ํ‰ ์ •๋ ฌํ•˜๋Š” justify-content

์ „์ฒด ๊ทธ๋ฆฌ๋“œ๋ฅผ ์ˆ˜ํ‰ ์ •๋ ฌํ•˜๋Š” justify-content, start ๊ฐ€ ๊ธฐ๋ณธ๊ฐ’์ด๋ฉฐ ์ „์ฒด ๊ทธ๋ฆฌ๋“œ๋ฅผ ์›€์ง์ด๊ฒŒ ํ•œ๋‹ค.

center, end, start, space-between ๋“ฑ์˜ ์†์„ฑ๋„ ๋„ฃ์–ด ๋ณด์•˜๋‹ค.

justify-content: start;

๐ŸŒต์ „์ฒด ๊ทธ๋ฆฌ๋“œ๋ฅผ ์ˆ˜์ง ์ •๋ ฌํ•˜๋Š” align-content

๊ทธ๋ฆฌ๋“œ์˜ ๋†’์ด๊ฐ€ ์ถฉ๋ถ„ํ•˜์ง€ ์•Š์œผ๋ฉด ์ˆ˜์ง ์ •๋ ฌ์„ ํ•ด๋„ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜ํƒ€๋‚˜์ง€ ์•Š๋Š”๋‹ค.

๋†’์ด๋ฅผ 250vh ์ •๋„๋กœ ์ˆ˜์ •ํ–ˆ๋‹ค.

๊ทผ๋ฐ flex ๋ฐฐ์šธ ๋•Œ align-items ์•„๋‹ˆ์˜€๋‚˜, ์–˜๋Š” align-content ๋ผ๊ณ  ์“ฐ๋Š”๊ตฌ๋‚˜?

์ „์ฒด ๊ทธ๋ฆฌ๋“œ๋ฅผ ์ˆ˜์ง ์ •๋ ฌํ•˜๋Š” align-content ๋„ start, end, center, space- ์จ๋จน์–ด ๋ณด์ž.

<div class="grid">
  <div class="header"></div>
  <div class="content"></div>
  <div class="nav"></div>
  <div class="footer"></div>
  <div class="header">header</div>
  <div class="content">content</div>
  <div class="nav">nav</div>
  <div class="footer">footer</div>
  <div class="header">header</div>
  <div class="content">content</div>
  <div class="nav">nav</div>
  <div class="footer">footer</div>
  <div class="header">header</div>
  <div class="content">content</div>
  <div class="nav">nav</div>
  <div class="footer">footer</div>
</div>
justify-content: start;
align-content: space-between;

align-content ๋ฅผ stretch ๋กœ ๋ฐ”๊พธ๊ณ  grid-template-rows ์— 100px ์„ 1fr ๋กœ ๋ฐ”๊ฟ”๋ณด์ž, ๋Š˜์–ด๋‚œ๋‹ค.

1

grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(4, 1fr);
align-content: stretch;

๐ŸŒตjustify-content ์™€ align-content ์˜ shortcut, place-content

place-content: ์ˆ˜์ง์ •๋ ฌ, ์ˆ˜ํ‰์ •๋ ฌ ์˜ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•œ๋‹ค.

place-content: end center;

๐ŸŒต๊ฒฐ๋ก 

place-items ์™€ place-content ๋Š” ์‚ฌ์šฉํ•˜๋Š” ์„ฑ๊ฒฉ์ด ๋‹ค๋ฅด๋‹ค๋Š” ์ ์„ ์—ผ๋‘ํ•ด์•ผ ํ•œ๋‹ค.

๐ŸŒตalign-self, justify-self, shortcut: place-self

์•„๋ž˜ ์ฝ”๋“œ ์ฐธ์กฐ

.header {
  background: #2ecc71;
  align-self: end;
  /* align ๊ทธ ์ž์ฒด์—๋งŒ ์ ์šฉ๋œ๋‹ค. */
  justify-self: center;

  /* align-self, justify-self ์˜ Shortcut ๋„ ์žˆ๋‹ค. */
  place-self: start end;
}
.content {
  background: #3498db;
}
.nav {
  background: #8e44ad;
}
.footer {
  background: #f39c12;
}

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

GitHubMediumTwitterFacebook