[TIL] 220205

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

TIL

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

📝 ė˜Ī늘 한 ęēƒ

  1. grid - place-content / place-self / grid-auto-rows / grid-auto-flow / grid-auto-columns

📚 ë°°ėšī ęēƒ

1. grid

1) place content

(1) justify-content

gridė˜ contentëĨž ėˆ˜í‰ė ėœžëĄœ ė •ë Ží•˜ęļ° ėœ„í•ī justify-contentëĨž ė‚ŽėšĐí•īė•ž 한ë‹Ī.

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

row뙀 columnė˜ 큎ęļ°ëĨž ė§€ė •í•˜ęļ° ėœ„í•ī fr ëŒ€ė‹  pixelė„ ė‚ŽėšĐ했ë‹Ī.

.grid {
  display: grid;
  gap: 10px;
  height: 50vh;
  grid-template-columns: repeat(4, 100px);
  grid-template-rows: repeat(4, 100px);
  justify-content: space-evenly;
  background: black;
}

justify-content: space-evenly

ëģīë‹Īė‹œí”ž justify-contentė˜ 값ęģžëŠ” 냁ęī€ė—†ėī grid container(ęē€ė •ėƒ‰ėœžëĄœ 표현된 div.grid)ė˜ 큎ęļ°ëŠ” ëģ€í•˜ė§€ ė•Šė•˜ë‹Ī.
justify-content는 gridė˜ contentëĨž ėˆ˜í‰ė ėœžëĄœ ė •ë Ží•˜ëŠ” ë°Đė‹ė— 똁í–Ĩė„ ëŊļėđ  ëŋėīë‹Ī.

(2) align-content

gridė˜ contentëĨž ėˆ˜ė§ė ėœžëĄœ ė •ë Ží•˜ęļ° ėœ„í•ī align-contentëĨž ė‚ŽėšĐí•īė•ž 한ë‹Ī.

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

뚜렷하ęēŒ ëđ„ęĩí•˜ęļ° ėœ„í•ī justify-content ė˜ˆė œė—ė„œ ė―”ë“œëĨž ė•―ę°„ ėˆ˜ė •í•īėĪŽë‹Ī.

.grid {
  display: grid;
  gap: 10px;
  height: 80vh;
  grid-template-columns: repeat(4, 50px);
  grid-template-rows: repeat(4, 50px);
  align-content: space-between;
  background: black;
}

align-content: space-between

ë§ˆė°Žę°€ė§€ëĄœ align-contentė˜ 값ęģžëŠ” 냁ęī€ė—†ėī grid container(ęē€ė •ėƒ‰ėœžëĄœ 표현된 div.grid)ė˜ 큎ęļ°ëŠ” ëģ€í•˜ė§€ ė•Šė•˜ë‹Ī.
align-content는 gridė˜ contentëĨž ėˆ˜ė§ė ėœžëĄœ ė •ë Ží•˜ëŠ” ë°Đė‹ė— 똁í–Ĩė„ ëŊļėđ  ëŋėīë‹Ī.

(3) place-content

place-content: align-content 값(눘링) justify-content 값(ėˆ˜í‰);

place-content: center end

.grid {
  display: grid;
  gap: 10px;
  height: 80vh;
  grid-template-columns: repeat(4, 50px);
  grid-template-rows: repeat(4, 50px);
  place-content: center end;
  background: black;
}

ðŸ’Ą place-items VS place-content
place-items VS place-content

gridė—ė„œ place-items뙀 place-contentëĨž ęĩŽëģ„í•īė•ž 한ë‹Ī.
place-items는 (ëđ„록 ė „ėēīė ėœžëĄœ 똑같ėī 렁ėšĐë ė§€ëžë„) ę·ļ ëŒ€ėƒėī 각 ė‚Žę°í˜• 하나하나ėļ 반ëĐī, place-content는 ëŠĻ든 ė‚Žę°í˜•ėīë‹Ī.

.grid {
  display: grid;
  gap: 10px;
  height: 80vh;
  grid-template-columns: repeat(4, 50px);
  grid-template-rows: repeat(4, 50px);
  place-content: center end; ❗
  place-items: center end; ❗
  background: black;
}

/* place-items가 렁ėšĐ될 눘 ėžˆë„ëĄ width뙀 heightëĨž ėķ”ę°€í–ˆë‹Ī */
.header {
  background-color: lightpink;
  width: 20px;
  height: 20px;
}

.content {
  background-color: lightskyblue;
  width: 20px;
  height: 20px;
}

.nav {
  background-color: lightseagreen;
  width: 20px;
  height: 20px;
}

.footer {
  background-color: mediumaquamarine;
  width: 20px;
  height: 20px;
}

2) place-self

í•˜ë‚˜ė˜ grid itemė—ë§Œ 렁ėšĐ하ęļ° ėœ„í•ī justify-self, align-selfëĨž ė‚ŽėšĐ할 눘 ėžˆë‹Ī.
ëķ€ëŠĻ ėŧĻ테ėī너가 ė•„ë‹Œ ėžė‹ ėŧĻ테ėīë„ˆė—ė„œ ė‚ŽėšĐí•ĻėœžëĄœėĻ ė „ėēī가 ė•„ë‹ˆëž í•˜ë‚˜ė˜ grid itemė—ë§Œ 氜ëģ„ė ėœžëĄœ 렁ėšĐ할 눘 ėžˆë‹Ī는 ė ė—ė„œ justify-items, align-items뙀 ęĩŽëģ„된ë‹Ī.

place-self

.grid {
  display: grid;
  gap: 10px;
  height: 80vh;
  grid-template-columns: repeat(4, 50px);
  grid-template-rows: repeat(4, 50px);
  place-content: center end;
  place-items: center end;
  background: black;
}

.header {
  background-color: lightpink;
  justify-self: start;
  align-self: end;
  width: 20px;
  height: 20px;
}

뎞률 justify-self뙀 align-self 또한 place-selfëĨž ėīėšĐí•ī 한ëēˆė— ėž‘ė„ąí•  눘 ėžˆë‹Ī.
( place-self: align-self 값(눘링) justify-self 값(ėˆ˜í‰); )


3) auto columns & rows

(1) auto columns & rows가 í•„ėš”í•œ ėī뜠

.item*32>{$}
.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, 50px);
  grid-template-rows: repeat(4, 50px);
}

.item:nth-child(odd) {
  background-color: greenyellow;
}

.item:nth-child(even) {
  background-color: darkcyan;
}

auto columns & rows가 í•„ėš”í•œ ėī뜠

element는 ë§Žė§€ë§Œ columns뙀 rowsëĨž 4ėĪ„ 4ėđļë°–ė— 만ë“Īė§€ ė•Šė•„ė„œ 17ëēˆė§ļ itemëķ€í„°ëŠ” text(ėˆŦėž)ė˜ height만큾만 ęģĩę°„ė„ ė°Ļė§€í•  ëŋėīë‹Ī. (한 ėĪ„ė˜ text가 ëŠĻ두 ė—†ė—ˆë‹ĪëĐī ę·ļ ėĪ„ė€ 화ëĐīė—ė„œ ëģīėīė§€ ė•Šė•˜ė„ ęēƒ.)

(2) grid-auto-rows

grid container뗐 grid-template-rowsëĨž ė‚ŽėšĐí•ī ė§€ė •í•œ ęēƒ ėīėƒėœžëĄœ 더 ë§Žė€ grid itemėī ėžˆė„ 때 í˜đė€ grid container뗐 grid-template-rowsëĨž ė•„ė˜ˆ ė‚ŽėšĐí•˜ė§€ ė•Šė•˜ė„ 때 grid-auto-rowsė˜ ę°’ė„ ęļ°ëģļę°’ėœžëĄœ ė‚ŽėšĐí•˜ė—Ž rowëĨž ėƒė„ąí•  눘 ėžˆë‹Ī.

grid-auto-rows

.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, 50px);
  grid-template-rows: repeat(4, 50px);
  grid-auto-rows: 50px; ❗
}

(3) grid-auto-flow: column / grid-auto-columns

grid container뗐 grid-auto-flow: columnė„ ė§€ė •í•˜ëĐī grid-template-rows뗐 ė˜í•ī ė§€ė •ëœ rowsė˜ 눘ëģīë‹Ī 더 ë§Žė€ div가 ėžˆė„ 때 ėķ”ę°€ė ėœžëĄœ rowsëĨž ėƒė„ąí•˜ė§€ ė•Šęģ  columnsëĨž ėƒė„ąí•œë‹Ī.
ėƒˆëĄ­ęēŒ ėƒė„ąëœ columns는 grid-auto-columnsė˜ ę°’ė„ ęļ°ëģļę°’ėœžëĄœ ė‚ŽėšĐ한ë‹Ī.

grid-auto-flow & grid-auto-columns

.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, 50px);
  grid-template-rows: repeat(4, 50px);
  grid-auto-flow: column; ❗
  grid-auto-columns: 50px; ❗
}

대ëķ€ëķ„ė˜ ęē―ėš°ė— grid-auto-rowsėī ė‚ŽėšĐë˜ė§€ë§Œ, ëŒ€í‘œė ėœžëĄœ 닮ë Ĩė„ 만ë“Ī 때 grid-auto-flow: columns뙀 grid-auto-columnsëĨž ė‚ŽėšĐ할 눘 ėžˆë‹Ī.


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

  1. grid
profile
dev log

0ę°œė˜ 댓ęļ€