[TIL] 220202

dev·2022년 2ė›” 2ėž
0

TIL

ëŠĐ록 ëģīęļ°
167/204
post-thumbnail

📝 ė˜Ī늘 한 ęēƒ

  1. grid

📚 ë°°ėšī ęēƒ

1. grid

1) grid가 í•„ėš”í•œ ėī뜠

flex container뗐 justify-content: space-betweenė„ ëķ€ė—Ží•œ ęē―뚰 레ėīė•„ė›ƒėī ė˜ë„í•˜ė§€ ė•Šė€ ëŠĻė–‘ėī 될 눘 ėžˆë‹Ī.

flexbox ëŽļ렜렐

ėš°ė„ , ė–‘ ė˜† 간ęēĐė€ ė‰―ęēŒ ėĄ°ė •í•  눘 ėžˆė§€ë§Œ ėœ„ ė•„ëž˜ 간ęēĐė€ ėžęī€ë˜ęēŒ í•œ ëēˆė— ėĄ°ė •í•  눘 ėžˆëŠ” 프로퍾티가 flexboxė—ëŠ” ė—†ęļ° ë•ŒëŽļ뗐 氜ëģ„ item뗐 marginė„ ëķ€ė—Ží•˜ëŠ” ė‹ėœžëĄœ ęĩŽí˜„í•īė•ž 한ë‹Ī.

또한, flex container뗐 justify-content: space-betweenęģž flex-wrap: wrapė„ í•Ļęŧ˜ ė§€ė •í–ˆë‹ĪëĐī ęē―ėš°ė— ë”°ëžė„œëŠ” ë§ˆė§€ë§‰ ėĪ„ė—ė„œëŠ” flex itemėī ė­‰ ë°°ėđ˜ë˜ė§€ ė•Šęģ  ę°€ėšī데가 ëđ„ė–ī ėžˆëŠ” ėą„ëĄœ ė–‘ ė˜†ėœžëĄœ ė •ë Žë  ėˆ˜ë„ ėžˆë‹Ī.

<div class="father">
  <div class="child">1</div>
  <div class="child">2</div>
  <div class="child">3</div>
  <div class="child">4</div>
  <div class="child">5</div>
</div>
.father {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.child {
  flex-basis: 30%;
  color: white;
  background-color: lightblue;
  font-size: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.child:nth-child(4) {
  margin-top: 10px;
}

ėī뙀 ę°™ė€ ëŽļ렜ëĨž í•īęē°í•˜ęļ° ėœ„í•īė„œëŠ” grid(ęēĐėž ëŽī늮)ëĨž ėīėšĐ하는 ęēŒ íŽļëĶŽí•˜ë‹Ī.

2) display: grid

display: flex뙀 ë§ˆė°Žę°€ė§€ëĄœ display: gridëĨž ëķ€ëŠĻ ėŧĻ테ėīë„ˆė— 렁ėšĐí•īė•ž 한ë‹Ī.
gridëĨž design하ęļ° ėœ„í•ī ë‹ĪëĨļ 프로퍾티ë“Ī 또한 대ëķ€ëķ„ė˜ ęē―뚰 ëķ€ëŠĻ ėŧĻ테ėīë„ˆė— ėķ”ę°€í•īė•ž 한ë‹Ī.

3) columns / rows

(1) grid-template-columns / rows / gap

grid-template-columns뙀 grid-template-rowsëĨž ėīėšĐí•ī grid containerė˜ column 및 rowė˜ ę°œėˆ˜ė™€ grid itemë“Īė˜ 너ëđ„ 및 높ėīëĨž ė„Īė •í•  눘 ėžˆë‹Ī.

/* grid container(ëķ€ëŠĻ ėŧĻ테ėī너) */
.father {
  display: grid;
  grid-template-columns: 250px 250px 250px; /* grid columnė˜ 氜눘 3氜, 하나ë‹đ 너ëđ„는 250px */
  gap: 10px; /* 또는 column-gap: 10px; row-gap: 10px; */
}

/* grid item */
.child {
  color: white;
  background-color: lightblue;
  font-size: 50px;
}

grid-template-rows 프로퍾티ëĨž ėķ”ę°€í•˜ė§€ ė•ŠėœžëĐī, grid itemė˜ 높ėī는 grid item뗐 ė§€ė •í•œ font-size í”„ëĄœíží‹°ė— 똁í–Ĩė„ 받는ë‹Ī.
grid itemė˜ font-sizeëĨž 5px로 ėĪ„ėīëĐī grid itemė˜ 각 높ėī도 ę·ļ뗐 따띾 ėĪ„ė–ī든ë‹Ī.

grid-template-rows: 100px 50px;

grid itemė˜ 높ėīëĨž 렜ė–ī하ęļ° ėœ„í•ī grid-template-columns í”„ëĄœíží‹°ė™€ ę°™ė€ ë°Đė‹ėœžëĄœ grid-template-rows 프로퍾티ëĨž ėķ”가할 눘 ėžˆë‹Ī.

(2) repeat()

grid itemë“Īėī ę°™ė€ 너ëđ„ í˜đė€ 높ėīëĨž ę°€ė§€ëŠ” ęē―뚰 grid-template-columns 또는 rows í”„ëĄœíží‹°ė˜ ę°’ėœžëĄœ 눘ėđ˜ëĨž 반ëģĩí•īė„œ ė ëŠ” ëŒ€ė‹ ė— repeat() í•Ļ눘ëĨž ė‚ŽėšĐ할 눘 ėžˆë‹Ī.

grid-template-columns: 250px 250px 250px;

/* ėœ„ė™€ ė•„ëž˜ëŠ” 같ë‹Ī */

grid-template-columns: repeat(3, 250px);

4) grid-template-areas

grid-template-areaëĨž ėīėšĐí•ī grid layoutė„ 만ë“Ī 눘 ėžˆë‹Ī.

(1) grid-template-columns / rows

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

gridëĨž ėīėšĐí•˜ė—Ž
ë§Ļ ėœ„ė— header
ėΑ氄뗐 container뙀 navigation
ë§Ļ ë°‘ė— footer
가 ė˜Ī도록 하ë Īęģ  í•œë‹Ī.

ėī때 ė•„ëž˜ėē˜ëŸžë§Œ ėž‘ė„ąí•˜ëĐī 화ëĐīė—ëŠ” ė•„ëŽīęēƒë„ ëœĻė§€ ė•ŠëŠ”ë‹Ī.

.grid {
  display: grid;
}

.header {
  background-color: lightpink;
}

.content {
  background-color: lightskyblue;
}

.nav {
  background-color: lightseagreen;
}

.footer {
  background-color: mediumaquamarine;
}

grid designė„ ėœ„í•īė„œëŠ” grid container(ëķ€ëŠĻ ėŧĻ테ėī너)ė—ëŠ” display: gridëĨž ė§€ė •í•˜ëŠ” ęēƒ ė™ļė—ë„ grid itemë“Īė˜ 큎ęļ°ëĨž ęē°ė •하ęļ° ėœ„í•œ 프로퍾티(grid-template-columns / rows)ëĨž ë°˜ë“œė‹œ 따로 맀렕í•īėĪ˜ė•ž 한ë‹Ī.

grid items

.grid {
  display: grid;
  /* ėķ”ę°€ */
  grid-template-columns: repeat(4, 200px);
  grid-template-rows: repeat(4, 200px);
}

(2) grid-template-areas / grid-area

grid container(ëķ€ëŠĻ ėŧĻ테ėī너)뗐 grid-template-columns / rowsëĨž ė§€ė •í•˜ė—Ž 4x4(16氜)ė˜ ė˜ė—­ė„ 만ë“Īė—ˆë‹Ī.

ëĻžė €, grid-template-areasëĨž ėīėšĐí•ī ėˆœė„œëŒ€ëĄœ 각 ė˜ė—­ė— ėīëĶ„ė„ ëķ™ė—Žė•ž 한ë‹Ī.

/* grid container(ëķ€ëŠĻ ėŧĻ테ėī너) */
.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 itemė—ëŠ” ėœ„ė—ė„œ ëķ™ėļ ėīëĶ„ë“Īė„ 맀렕í•īė•ž 한ë‹Ī.
ėīí•īëĨž 돕ęļ° ėœ„í•ī classėīëĶ„ęģž grid-areaė˜ ėīëĶ„ė„ ë™ėží•˜ęēŒ ėž‘ė„ąí–ˆė§€ë§Œ ë‘˜ė€ ė „í˜€ 냁ęī€ėī ė—†ë‹Ī.

.header {
  background-color: lightpink;
  grid-area: header;
}

.content {
  background-color: lightskyblue;
  grid-area: content;
}

.nav {
  background-color: lightseagreen;
  grid-area: nav;
}

.footer {
  background-color: mediumaquamarine;
  grid-area: footer;
}

ë‹ĪėŒęģž ę°™ė€ ęē°ęģžëŽžė„ ė™„ė„ąí–ˆë‹Ī.

grid layout

ėī는 ė‹Īė œëĄœ ė˜ĪëĨļėŠ― ę·ļëĶžėē˜ëŸž 16ę°œė˜ ė˜ė—­ėœžëĄœ 나뉘ė–īė ļ ėžˆë‹Ī.
gridëĨž ėīėšĐí•ī ėīėē˜ëŸž ė‰―ęēŒ layoutė„ ė™„ė„ąí•  눘 ėžˆë‹Ī.

grid layout ė˜ė—­


âœĻ ë‚īėž 할 ęēƒ

  1. grid
profile
dev log

0ę°œė˜ 댓ęļ€