[TIL] 220206

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

TIL

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

📝 ė˜Ī늘 한 ęēƒ

  1. grid - minmax() / auto-fill, auto-fit / min-content, max-content

📚 ë°°ėšī ęēƒ

1. grid

1) minmax()

minmax()ëĨž ėīėšĐí•ī grid itemė˜ ėĩœė†Ÿę°’ęģž ėĩœëŒ“ę°’ė„ ė •í•  ėˆ˜ ėžˆë‹Ī.

ė˜ˆëĨž ë“Īė–ī, grid itemė˜ 너ëđ„ëĨž 가ëŠĨ한 한 큎ęēŒ 만ë“Īęģ  ė‹ķė§€ë§Œ 100px ėī하로는 ėž‘ė•„ė§€ė§€ ė•Šęļ°ëĨž ė›í•  때 minmax(100px, 1fr) ėī띞ęģ  ė„Īė •í•  ėˆ˜ ėžˆë‹Ī.

grid-template-columns: repeat(4, minmax(100px, 1fr));
grid-auto-flow: column;
grid-auto-columns: minmax(100px, 1fr);

2) auto-fill / auto-fit

auto-fillęģž auto-fitė€ repeat()ė—ė„œë§Œ ė‚ŽėšĐ한ë‹Ī.

ėž‘ė€ 화ëĐīė—ė„œëŠ” auto-fillęģž auto-fitė€ ė°Ļėī가 ė—†ë‹Ī.
ę·ļ럮나, grid itemė˜ ėˆ˜ëģīë‹Ī 화ëĐīė˜ 큎ęļ°ę°€ ėŧĪė§€ëĐī auto-fillęģž auto-fitė€ ė°ĻėīëĨž ëģīėļë‹Ī.

grid itemė˜ ėˆ˜ë‚˜ 큎ęļ°ëĨž ė‚Žė „ė— ė•Œ ėˆ˜ ė—†ęą°ë‚˜ 반ė‘형 디ėžėļė„ 할 때 ėœ ėšĐ하ęēŒ ėīėšĐ할 ėˆ˜ ėžˆë‹Ī.

(1) auto-fill

.grid {
  display: grid;
  gap: 10px;
  grid-auto-rows: 100px;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}

rowëĨž columns로 ėą„ėšīë‹Ī.
ėœ„ė™€ 같ėī grid itemė˜ ėˆ˜ę°€ ė ė–īė„œ rowëĨž ë‹Ī ėą„ėš°ė§€ ëŠŧ한ë‹ĪëĐī ëđˆ columns로띾도 rowëĨž ë‹Ī ėą„ėšīë‹Ī.

(2) auto-fit

.grid__second {
  display: grid;
  gap: 10px;
  grid-auto-rows: 100px;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}

rowė— 딱 맞도록 현ėžŽ grid itemë“Īė„ 늘ëĶ°ë‹Ī.

3) min-content / max-content

repeat(), minmax()ė™€ í•Ļęŧ˜ ė‚ŽėšĐí•ĻėœžëĄœėĻ ė™„ëē―하ęēŒ 반ė‘형 디ėžėļė„ ęĩŽí˜„í•  ėˆ˜ ėžˆë‹Ī.

(1) min-content

min-content는 ė–īė ˆ ë‹Ļėœ„ëĄœ 끊ė—ˆė„ 때 가ėžĨ ęļī ë‹Ļė–īëĨž ęļ°ėĪ€ėœžëĄœ 하는 ėĩœė†Œ 너ëđ„ëĨž 말한ë‹Ī.
boxëĨž content가 ėž‘ė•„ė§ˆ ėˆ˜ ėžˆëŠ” 만큾 ėž‘ęēŒ 만든ë‹Ī.

(2) max-content

max-content는 content가 wrap 되ė§€ ė•Šęļ° ėœ„í•ī 필ėš”í•œ ėĩœëŒ€ 높ėī í˜đė€ 너ëđ„ëĨž 말한ë‹Ī.
boxëĨž contentëĨž 폎í•Ļ하ęļ° ėœ„í•ī 필ėš”í•œ 만큾 큎ęēŒ 만든ë‹Ī.

(3) 반ė‘형 디ėžėļ

gridëĨž ėīėšĐí•ī 반ė‘형 디ėžėļė„ ęĩŽí˜„í•īëģīë Īęģ  한ë‹Ī.

<div class="grid">
  <div class="item">Lorem ipsum dolor sit amet.</div>
  <div class="item">Lorem, ipsum dolor sit amet consectetur</div>
  <div class="item">Lorem, ipsum dolor.</div>
  <div class="item">
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Quasi
  </div>
</div>
.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(max-content, 1fr)); ðŸ’Ą
  grid-auto-rows: 100px;
}

grid itemė˜ columnė˜ 너ëđ„ė˜ ėĩœė†Ÿę°’ė€ content가 wrap 되ė§€ ė•Šęļ° ėœ„í•ī 필ėš”í•œ ėĩœëŒ€ę°’(max-content)로 ė„Īė •í•˜ęģ , grid itemė˜ columnė˜ 너ëđ„ė˜ ėĩœëŒ“ę°’ė€ 1fr로 ė„Īė •í–ˆë‹Ī.

1, 2, 4ëēˆė§ļ div는 ė „ėžę°€, 3ëēˆė§ļ div는 후ėžę°€ ė ėšĐ된 ęēƒė„ 확ėļ할 ėˆ˜ ėžˆë‹Ī.

한íŽļ, auto-fit, minmax, max-contentëĨž 혞ėšĐ하ė—Ž 또 ë‹ĪëĨļ 반ė‘형 디ėžėļė„ ęĩŽí˜„í•  ėˆ˜ ėžˆë‹Ī.

.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(120px, max-content));
  grid-auto-rows: 100px;
}

ėœ„ ęē―ėš°ė—ëŠ” auto-fitė„ ė§€ė •í–ˆęļ° 때ëŽļė— rowė— 딱 맞도록 현ėžŽ grid itemë“Īėī 늘ė–ī나ė•ž 한ë‹Ī.
ę·ļ럮나 minmax(120px, max-content)로 ėļí•ī grid itemė€ 120px ėī하로는 ėž‘ė•„ė§ˆ ėˆ˜ ė—†ęģ , 'max-content ėīėƒėœžëĄœëŠ” ėŧĪė§ˆ ėˆ˜ ė—†ë‹Ī.'


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

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

0개ė˜ 댓ęļ€