2μ°¨μμ μΌλ‘ μνκ³Ό μμ§μ λμμ λλ μ μλ λ μ΄μμ λ°©λ² μ λλ€.
display : grid , column κ³Ό rows
<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">4</div>
<div class="child">4</div>
<div class="child">4</div>
<div class="child">4</div>
</div>
.father{
display: grid; /* μμμ λΆλͺ¨μκ² μ μΈ */
grid-template-columns:250px 250px 250px; /* μνλ μ΄λ§νΌ μ
λ ₯ νλ€ */
grid-template-rows: 100px 80px 300px; /*μνλ rowμ ν¬κΈ°λ₯Ό μ
λ ₯ */
column-gap: 10px; /* column κ°μ μ°¨μ΄ */
row-gap: 10px;
}
.child{
flex-basis: 300px;
background: peru;
color: white;
font-size: 50px;
}
repeat
.grid{
display: grid;
grid-template-columns: 200px 200px 200px 200px;
grid-template-rows: 300px 300px 300px 300px;
}
- λ§€λ² λ°λ³΅νλ©΄μ λ§λ€λ©΄ μ€λκ±Έλ¦¬κ³ ν¨μ¨μ μ΄μ§ μμ΅λλ€.
- κ·Έλμ, repeatμ μ¬μ©νμ¬ λΉ λ₯΄κ³ κ°νΈνκ² λνλΌ μ μμ΅λλ€.
.grid{
display: grid;
grid-template-columns: repeat(4, 200px);
grid-template-rows: repeat(4, 300px);
}
grid-template-areas
- λ§μλλ‘ grid ν νλ¦Ώμ λμμΈ ν μ μμ΅λλ€.
.grid{
display: grid;
grid-template-columns: repeat(4, 200px);
grid-template-rows: 100px repeat(2, 200px) 100px;
grid-template-areas:
"header header header header"
"content content content nav"
"content content content nav"
"footer footer footer footer";
}
.header{
background-color: #2ecc71;
grid-area: header;
}
.content{
background-color: #3498db;
grid-area: content;
}
.nav{
background-color: #8e44ad;
grid-area: nav;
}
.footer{
background-color: peru;
grid-area: footer;
}
- μ£Όμν μ μ
grid-area
λ₯Ό ν΅ν΄header
κ° λ¬΄μμΈμ§,content
κ° λ¬΄μμΈμ§,footer
κ° λ¬΄μμΈμ§ μμμκ² μ μΈν΄μΌ ν©λλ€.
Rows and Columns
- grid-column-star
- grid-column-end
- grid-row-start
- gird-row-end
νΉμ§
- grid-template-aresμ λΉμ·ν κΈ°λ₯μ νλ μμ± μ λλ€.
- columnκ³Ό rowκ° μλ μ€ μ μμκ³Ό λμ μ ν©λλ€.
- κ·Έλ¦Όμ 보면μ μ΄ν΄ νλ©΄ λ μ½μ΅λλ€.
<div class="grid">
<div class="header"></div>
<div class="content"></div>
<div class="nav"></div>
<div class="footer"></div>
</div>
.grid{
display: grid;
grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(4, 100px);
}
.header{
background-color: #2ecc71;
grid-column-start: 1;
grid-column-end: 3;
}
.grid{
display: grid;
grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(4, 100px);
}
.header{
background-color: #2ecc71;
grid-column-start: 1;
grid-column-end: 5;
}
.content{
background-color: #3498db;
grid-column-start: 1;
grid-column-end: 4;
grid-row-start: 2;
grid-row-end: 4;
}
.nav{
background-color: #8e44ad;
}
.footer{
background-color: peru;
}
content
λ₯Ό κΈ°μ€μΌλ‘grid-row
λ₯Ό 보면 λ©λλ€.(νλμ)
μ λ°μ μΌλ‘
- grid κ° λ¬΄μμΈμ§, μ΄λ»κ² μ¬μ©νλμ§ μ 리 νμμ΅λλ€.
flexbox
μjustify-items & align-items
μ²λΌ item λ€μ μ΄λ μν¬ μ μμ΅λλ€.- λν
justify-content & align-content
μμ±μ μ¬μ©νμ¬ grid μ 체μ μμΉλ₯Ό μ΄λ ν μ μμ΅λλ€.- itemμ μ νλνλ, contentλ grid μ 체
μ°Έκ³
'π Front-End > CSS' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
em & rem (0) | 2022.10.20 |
---|---|
Flex (0) | 2022.10.20 |
position μμ± (0) | 2022.10.19 |
display μμ± (0) | 2022.10.19 |
Box Model & box-sizing (0) | 2022.10.19 |