February 20, 2021
html μ μλμ κ°μ΄ μ μ©νμλ€.
<body>
auto-fill
<div class="grid">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
auto-fit
<div class="grid">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
</body>
css μ μ΄κΈ° μ½λλ λ€μκ³Ό κ°λ€.
.grid {
display: grid;
gap: 5px;
height: 50vh;
grid-auto-rows: 100px;
}
.grid:first-child {
grid-template-columns: repeat(5, minmax(100px, 1fr));
}
.grid:last-child {
grid-template-columns: repeat(5, minmax(100px, 1fr));
}
.item:nth-child(odd) {
background: #2ecc71;
}
.item:nth-child(even) {
background: #3498db;
}
μμ§κΉμ§λ μμ μλκ° λμΌνλ€.
auto-fill μ λΉ μ»¬λΌμ΄(곡κ°) μλ λ§νΌ κ°λ₯ν λ§μ΄ μ±μ΄λ€. λ³΄λ€ μ νν μ¬μ΄μ¦λ₯Ό μν λ μ¬μ©νλ€.
.grid:first-child {
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}
auto-fit μμ±μ νμ¬μ element λ₯Ό μ λλ €μ row μ λ± λ§κ² (fit) νλ κ²μ΄λ€.
λ°μνμμ μ λμ μΈ μ¬μ΄μ¦λ₯Ό μν κ², auto-fit μ λΉ κ³΅κ°μ΄ μλ€!
.grid:last-child {
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}
λͺ¨λ°μΌ λ°μνμμ νλ©΄μ ν€μλκ° λ
element λ€μ κ°μ μ¬μ΄μ¦λ‘ λ§μΆκ² νκ±°λ (auto-fill)
element λ€μ ν¬κΈ°λ λμμ 컀μ‘μΌλ©΄ νλκ° (auto-fit) μ μ°¨μ΄μ΄λ€.