[TIL] 220202

Lee Syong·2022년 2ė›” 2ėž
0

TIL

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

📝 ė˜Ī늘 한 ęēƒ

  1. grid

📚 ë°°ėšī ęēƒ

1. grid

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

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

ėš°ė„ , ė–‘ ė˜† 간ęēĐė€ ė‰―ęēŒ ėĄ°ė •í•  ėˆ˜ ėžˆė§€ë§Œ ėœ„ ė•„래 간ęēĐė€ ėžęī€ë˜ęēŒ 한 ëēˆė— ėĄ°ė •í•  ėˆ˜ ėžˆëŠ” 프로퍾티가 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 {
  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;
}

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

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


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

  1. grid
profile
ëŠĨ동ė ėœžëĄœ ė‚īėž, 행ëģĩ하ęēŒðŸ˜

0개ė˜ 댓ęļ€