[TIL] 220205

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

(3) place-content

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

.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

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ė™€ ęĩŽëģ„된ë‹Ī.

.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;
}

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 {
  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 {
  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
ëŠĨ동ė ėœžëĄœ ė‚īėž, 행ëģĩ하ęēŒðŸ˜

0개ė˜ 댓ęļ€