GRID λ μ΄μμ
β’
미리보기
β’
κ°λ
β’
ν΅μ¬μμ
β’
μ€μ΅μμ
β’
Quiz
미리보기
Grid λ μ΄μμμ μ¬μ©ν΄λ³΄λ©΄μ μ½κ² μ΄ν΄ν΄λ΄
λλ€.
Layoutit Grid
angrytools css-grid
κ°λ
Grid Layoutμ 격μ λ μ΄μμμ μλ―Ένλ©°, μμλ€μ 2μ°¨μμΌλ‘ λ°°μΉνλ λ° μ΅μ νλ λ°©λ²μ
λλ€.
Grid λ μ΄μμμ μ¬μ©νλ©΄ μ¬μ΄νΈμ 볡μ‘ν ꡬ쑰λ₯Ό κ°νΈνκ² κ΅¬μ±ν μ μμ΅λλ€. μλ₯Ό λ€μ΄, μΉ νμ΄μ§λ₯Ό μ¬λ¬ ꡬμμΌλ‘ λλμ΄ λ°°μΉν μ μμ΅λλ€.
Grid λ μ΄μμ μμ 1 - μΉ νμ΄μ§ λ μ΄μμ μμ
β’
ν€λ
β’
μ¬μ΄λλ°
β’
μ½ν
μΈ μμ
β’
νΈν°
μ΄λ κ² 4κ°μ μμμ μ€μ νκ³ , κ° μμμ ν¬κΈ°μ μμΉλ₯Ό μ§μ ν μ μμ΅λλ€. νΉμ λ μ΄μμμ μν κ²½μ°, λ€μκ³Ό κ°μ΄ display: grid;μ grid-template-columns μμ±μ μ¬μ©νμ¬ μ½κ² μ€μ ν μ μμ΅λλ€.
μλ₯Ό λ€μ΄, ν€λμ νΈν°λ μ 체 νμ μ°¨μ§νκ³ , μ¬μ΄λλ°λ μΌμͺ½μ, μ½ν
μΈ μμμ μ€λ₯Έμͺ½μ μμΉνλλ‘ νκ³ μΆλ€λ©΄, μλμ κ°μ΄ CSSλ₯Ό μ μ©ν μ μμ΅λλ€:
.container {
display: grid;
grid-template-columns: 1fr 3fr; /* μ¬μ΄λλ°μ μ½ν
μΈ μμ λΉμ¨ μ€μ */
grid-template-rows: auto 1fr auto; /* ν€λ, μ½ν
μΈ , νΈν° μ€μ */
}
CSS
볡μ¬
μ΄λ κ² νλ©΄ 볡μ‘ν λ μ΄μμμ μ½κ² μ€μ ν μ μμ΅λλ€. Grid λ μ΄μμμ λ€μν λ°μν λμμΈμλ μ μ©νκ² μ¬μ©λ©λλ€.
Grid λ μ΄μμ μμ 2 - μΌνλͺ° μν λͺ©λ‘
Grid Layoutμ μ¬μ©νμ¬ μΌνλͺ° μν λͺ©λ‘μ ꡬμ±ν μ μμ΅λλ€. μν λͺ©λ‘μ μ¬λ¬ μνμ 격μ ννλ‘ λ°°μΉνμ¬ λ³΄κΈ° μ’κ² μ λ ¬ν μ μμ΅λλ€.
μλ₯Ό λ€μ΄, μΌνλͺ°μ μν λͺ©λ‘ λ μ΄μμμ λ€μκ³Ό κ°μ΄ ꡬμ±ν μ μμ΅λλ€:
β’
μν μΉ΄λ 1
β’
μν μΉ΄λ 2
β’
μν μΉ΄λ 3
β’
μν μΉ΄λ 4
β’
μν μΉ΄λ 5
β’
μν μΉ΄λ 6
μ΄λ κ² 6κ°μ μν μΉ΄λλ₯Ό 3μ΄λ‘ λ°°μΉνκ³ μΆλ€λ©΄, display: grid;μ grid-template-columns μμ±μ μ¬μ©νμ¬ μ½κ² μ€μ ν μ μμ΅λλ€.
.product-list {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3μ΄λ‘ λ°°μΉ */
gap: 16px; /* μΉ΄λ κ°μ κ°κ²© */
}
CSS
볡μ¬
<div class="product-list">
<div class="product-card">μν μΉ΄λ 1</div>
<div class="product-card">μν μΉ΄λ 2</div>
<div class="product-card">μν μΉ΄λ 3</div>
<div class="product-card">μν μΉ΄λ 4</div>
<div class="product-card">μν μΉ΄λ 5</div>
<div class="product-card">μν μΉ΄λ 6</div>
</div>
CSS
볡μ¬
μ΄λ κ² νλ©΄ μν μΉ΄λκ° 3μ΄λ‘ μ λ ¬λκ³ , μλμΌλ‘ λμ΄κ° λ§μΆ°μ Έμ 보기 μ’μ μν λͺ©λ‘μ΄ μμ±λ©λλ€. Grid Layoutμ μ¬μ©νλ©΄ λ€μν λ μ΄μμμ μ μ°νκ² κ΅¬μ±ν μ μμ΄ μΌνλͺ° λμμΈμ λ§€μ° μ μ©ν©λλ€.
ν΅μ¬ μμ
Grid Layoutμ μ μ©νλ ν΅μ¬ μμλ Containerμ Itemμ
λλ€.
β’
Grid Container
β’
Grid Item
Grid Container
Containerλ Itemλ€μ λ΄λ μμμΌλ‘, 2μ°¨μ 격μ ννλ‘ μμλ₯Ό λ°°μΉν λ°©ν₯μ μ μν©λλ€. νκ³Ό μ΄μ μ€μ νμ¬ κ° Itemμ ν¬κΈ°μ μμΉλ₯Ό μ‘°μ ν μ μμ΅λλ€.
Grid Containerμμλ νκ³Ό μ΄μ μ, ν¬κΈ°, κ°κ²©μ μ μνλ μμ±μ μ¬μ©νμ¬ λ³΅μ‘ν λ μ΄μμμ μ½κ² ꡬμ±ν μ μμ΅λλ€. Gridμ κ°λ ₯ν κΈ°λ₯μ μ΄ν΄νλ κ²μ΄ μ€μν©λλ€.
Grid Item
Containerμ λ΄κΈ°λ κ°λ³ μμλ€μ
λλ€. Itemμ κ°λ³μ μΌλ‘ ν¬κΈ°μ μμΉλ₯Ό μ€μ ν μ μμΌλ©°, λ€μν λ°©μμΌλ‘ λ°°μΉν μ μμ΅λλ€.
Grid Layoutμ μ¬μ©νλ©΄ κ° Itemμ λ€μν λ°©μμΌλ‘ μ λ ¬νκ³ λ°°μΉν μ μμ΄, 볡μ‘ν μΉ λ μ΄μμμ μ½κ² ꡬνν μ μμ΅λλ€.
μ©μ΄ | μ€λͺ
|
그리λ 컨ν
μ΄λ | 그리λ μμ΄ν
μ ν¬ν¨νλ μμμΌλ‘, 2μ°¨μ λ μ΄μμμ μ€μ νλ μν μ ν©λλ€. |
그리λ μμ΄ν
| 그리λ 컨ν
μ΄λ λ΄μμ λ°°μΉλλ κ°λ³ μμλ‘, κ°κ°μ ν¬κΈ°μ μμΉλ₯Ό μ μν μ μμ΅λλ€. |
그리λ λ²νΈ | 그리λμ κ° μμ΄ν
μ λΆμ¬λλ κ³ μ ν λ²νΈλ‘, μμ΄ν
μ μμΉλ₯Ό μλ³νλ λ° μ¬μ©λ©λλ€. |
그리λ λΌμΈ | 그리λμ νκ³Ό μ΄μ ꡬλΆνλ κ°μμ μ μΌλ‘, μμ΄ν
μ λ°°μΉμ λμμ μ€λλ€. |
그리λμ
| 그리λμ ν μΉΈμ μλ―Ένλ©°, μμ΄ν
μ΄ μμΉν μ μλ κΈ°λ³Έ λ¨μμ
λλ€. |
그리λκ° | 그리λ μμ΄ν
κ°μ κ°κ²©μ μ μνλ μμ±μΌλ‘, νκ³Ό μ΄ μ¬μ΄μ 곡κ°μ μ‘°μ ν©λλ€. |
Grid Container μ μ£Όμ μμ±
μμ± | μ€λͺ
|
display | 그리λ 컨ν
μ΄λ(Container)λ₯Ό μ μ |
grid-template | grid-template-xxxμ λ¨μΆ μμ± |
grid-template-rows | λͺ
μμ ν(Track)μ ν¬κΈ°λ₯Ό μ μ |
grid-template-columns | λͺ
μμ μ΄(Track)μ ν¬κΈ°λ₯Ό μ μ |
grid-template-areas | μμ(Area) μ΄λ¦μ μ°Έμ‘°ν΄ ν
νλ¦Ώ μμ± |
gap(grid-gap) | xxx-gapμ λ¨μΆ μμ± |
row-gap
(grid-row-gap) | νκ³Ό ν μ¬μ΄μ κ°κ²©(Line)μ μ μ |
column-gap
(grid-column-gap) | μ΄κ³Ό μ΄ μ¬μ΄μ κ°κ²©(Line)μ μ μ |
μμ± | μ€λͺ
|
grid-auto-rows | μμμ μΈ ν(Track)μ ν¬κΈ°λ₯Ό μ μ |
grid-auto-columns | μμμ μΈ μ΄(Track)μ ν¬κΈ°λ₯Ό μ μ |
grid-auto-flow | μλ λ°°μΉ μκ³ λ¦¬μ¦ λ°©μμ μ μ |
grid | grid-template-xxxκ³ΌΒ grid-auto-xxxμ λ¨μΆ μμ± |
align-content | 그리λ μ½ν
μΈ (Grid Contents)λ₯Ό μμ§(μ΄ μΆ) μ λ ¬ |
justify-content | 그리λ μ½ν
μΈ λ₯Ό μν(ν μΆ) μ λ ¬ |
place-content | align-contentμΒ justify-contentμ λ¨μΆ μμ± |
align-items | 그리λ μμ΄ν
(Items)λ€μ μμ§(μ΄ μΆ) μ λ ¬ |
justify-items | 그리λ μμ΄ν
λ€μ μν(ν μΆ) μ λ ¬ |
place-items | align-itemsμΒ justify-itemsμ λ¨μΆ μμ± |
fr (fractional unit; λ¨μ λΆμ;)
λΆμκ° 1μ΄κ³ λΆλͺ¨κ° μμ μ μμΈ λΆμ
β’
λ¨μ 곡κ°μ λλμ΄ κ°λ λΉμ¨
fraction
: λΆμ
display: grid & display: inline-grid
μμ±κ° | μ€λͺ
|
grid | Block νΉμ±μ Grid Containerλ₯Ό μ μ |
inline-grid | Inline νΉμ±μ Grid Containerλ₯Ό μ μ |
.container {
display: grid;
}
.container {
display: inline-grid;
}
CSS
볡μ¬
grid-template-rows
λΌμΈμ μ΄λ¦κ³Ό νμ ν¬κΈ°λ₯Ό μ§μ νλ μμ±
β’
fr (fraction) λ¨μ μ¬μ©κ°λ₯
β’
repeat() ν¨μ μ¬μ©κ°λ₯
.container {
display: grid;
grid-template-rows: 100px 200px auto; /* 3κ°μ νμ μ μ (1ν: 100px, 2ν: 200px, 3ν: μλ λμ΄) */
grid-gap: 16px; /* μμ΄ν
κ°μ κ°κ²© μ€μ */
}
CSS
볡μ¬
<div class="container">
<div class="item1">μμ΄ν
1</div>
<div class="item2">μμ΄ν
2</div>
<div class="item3">μμ΄ν
3</div>
</div>
HTML
볡μ¬
grid-template-columns
λΌμΈμ μ΄λ¦κ³Ό μ΄μ ν¬κΈ°λ₯Ό μ§μ νλ μμ±
β’
fr (fraction) λ¨μ μ¬μ©κ°λ₯
β’
repeat() ν¨μ μ¬μ©κ°λ₯
.container {
display: grid;
grid-template-columns: 1fr 2fr; /* 2κ°μ μ΄μ μ μ (1μ΄: 1fr, 2μ΄: 2fr) */
grid-gap: 16px; /* μμ΄ν
κ°μ κ°κ²© μ€μ */
}
CSS
볡μ¬
<div class="container">
<div class="item1">μμ΄ν
1</div>
<div class="item2">μμ΄ν
2</div>
</div>
HTML
볡μ¬
grid-template
grid-template-rows, grid-template-columns λ₯Ό λμμ μ§μ νλ λ¨μΆ μμ±
grid-template-rows grid-template-columns grid-template-areas λ¨μΆ μμ±
β’
grid-template-rows, grid-template-columns
.container {
display: grid;
grid-template: auto 200px / 1fr 2fr 1fr; /* νκ³Ό μ΄μ λμμ μ μ */
grid-gap: 16px; /* μμ΄ν
κ°μ κ°κ²© μ€μ */
}
CSS
볡μ¬
<div class="container">
<div class="item1">μμ΄ν
1</div>
<div class="item2">μμ΄ν
2</div>
<div class="item3">μμ΄ν
3</div>
<div class="item4">μμ΄ν
4</div>
</div>
HTML
볡μ¬
β’
grid-template-rows, grid-template-columns, grid-template-areas
.container {
display: grid;
grid-template:
"header header header" 100px /* 1ν: ν€λ μμ, λμ΄ 100px */
"sidebar content content" 1fr /* 2ν: μ¬μ΄λλ°μ μ½ν
μΈ μμ */
"footer footer footer" 50px; /* 3ν: νΈν° μμ, λμ΄ 50px */
grid-template-columns: 200px 1fr 1fr; /* 3κ°μ μ΄ μ μ */
grid-gap: 16px; /* μμ΄ν
κ°μ κ°κ²© μ€μ */
}
CSS
볡μ¬
<div class="container">
<div class="header">ν€λ</div>
<div class="sidebar">μ¬μ΄λλ°</div>
<div class="content">μ½ν
μΈ </div>
<div class="footer">νΈν°</div>
</div>
HTML
볡μ¬
grid-template-areas
λλΈ ν΄λ¦!
λλΈ ν΄λ¦!
Grid λ μ΄μμμ μμμ μ§μ νλ μμ±
Grid μμ΄ν
μμ grid-area μμ±μ μ¬μ©νμ¬, μ§μ ν νλͺ©μ μ΄λ¦μ μ°Έμ‘°νμ¬ μμμ μ§μ νλ€.
. κΈ°νΈλ₯Ό μ¬μ©νμ¬ λΉ μμμ μ§μ ν μ μλ€.
.container {
display: grid;
grid-template-areas:
"header header header"
"sidebar content content"
"footer footer footer";
grid-template-columns: 200px 1fr 1fr; /* 3κ°μ μ΄ μ μ */
grid-template-rows: 100px 1fr 50px; /* 3κ°μ ν μ μ */
grid-gap: 16px; /* μμ΄ν
κ°μ κ°κ²© μ€μ */
}
CSS
볡μ¬
<div class="container">
<div class="header" style="grid-area: header;">ν€λ</div>
<div class="sidebar" style="grid-area: sidebar;">μ¬μ΄λλ°</div>
<div class="content" style="grid-area: content;">μ½ν
μΈ </div>
<div class="footer" style="grid-area: footer;">νΈν°</div>
</div>
HTML
볡μ¬
row-gap (grid-row-gap)
Grid λ μ΄μμμμ ν μ¬μ΄μ κ°κ²©μ μ§μ νλ μμ±
default: 0
column-gap (grid-column-gap)
Grid λ μ΄μμμμ μ΄ μ¬μ΄μ κ°κ²©μ μ§μ νλ μμ±
default: 0
gap(grid-gap)
row-gap, column-gap λμμ μ§μ νλ λ¨μΆ μμ±
.container {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3κ°μ μ΄ μ μ */
grid-template-rows: repeat(2, 100px); /* 2κ°μ ν μ μ */
gap: 16px; /* μμ΄ν
κ°μ κ°κ²© μ€μ */
}
CSS
볡μ¬
<div class="container">
<div class="item1" style="background-color: lightcoral;">μμ΄ν
1</div>
<div class="item2" style="background-color: lightblue;">μμ΄ν
2</div>
<div class="item3" style="background-color: lightgreen;">μμ΄ν
3</div>
<div class="item4" style="background-color: lightyellow;">μμ΄ν
4</div>
<div class="item5" style="background-color: lightpink;">μμ΄ν
5</div>
<div class="item6" style="background-color: lightgray;">μμ΄ν
6</div>
</div>
HTML
볡μ¬
grid-auto-rows
ν¬κΈ°κ° μ€μ λμ§ μμ νμ ν¬κΈ°λ₯Ό μ§μ νλ μμ±
.container {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3κ°μ μ΄ μ μ */
grid-auto-rows: 100px; /* μλμΌλ‘ μμ±λ νμ λμ΄λ₯Ό 100pxλ‘ μ€μ */
gap: 16px; /* μμ΄ν
κ°μ κ°κ²© μ€μ */
}
CSS
볡μ¬
<div class="container">
<div class="item1" style="background-color: lightcoral;">μμ΄ν
1</div>
<div class="item2" style="background-color: lightblue;">μμ΄ν
2</div>
<div class="item3" style="background-color: lightgreen;">μμ΄ν
3</div>
<div class="item4" style="background-color: lightyellow;">μμ΄ν
4</div>
<div class="item5" style="background-color: lightpink;">μμ΄ν
5</div>
<div class="item6" style="background-color: lightgray;">μμ΄ν
6</div>
</div>
HTML
볡μ¬
grid-auto-columns
ν¬κΈ°κ° μ€μ λμ§ μμ μ΄μ ν¬κΈ°λ₯Ό μ§μ νλ μμ±
.container {
display: grid;
grid-auto-columns: 150px; /* μλμΌλ‘ μμ±λ μ΄μ λλΉλ₯Ό 150pxλ‘ μ€μ */
grid-auto-flow: column; /* μ΄ λ°©ν₯μΌλ‘ μμ΄ν
μ μΆκ° */
gap: 16px; /* μμ΄ν
κ°μ κ°κ²© μ€μ */
}
CSS
볡μ¬
<div class="container">
<div class="item1" style="background-color: lightcoral;">μμ΄ν
1</div>
<div class="item2" style="background-color: lightblue;">μμ΄ν
2</div>
<div class="item3" style="background-color: lightgreen;">μμ΄ν
3</div>
<div class="item4" style="background-color: lightyellow;">μμ΄ν
4</div>
</div>
HTML
볡μ¬
grid-auto-flow
ν¬κΈ°λ μμμ μ§μ νμ§ μμ μμ΄ν
μ΄ κ·Έλ¦¬λμ μ½μ
λλ λ°©μμ μ§μ νλ μμ±
μμ±κ° | μλ―Έ |
row | κ° ν μΆμ λ°λΌ μ°¨λ‘λ‘ λ°°μΉ (β β) |
column | κ° μ΄ μΆμ λ°λΌ μ°¨λ‘λ‘ λ°°μΉ (β β) |
row dense | ν μΆμ λ°λΌ λ°°μΉ, μ μ νμ λΉ μμμ μ±μ |
column dense | μ΄ μΆμ λ°λΌ λ°°μΉ, μ μ μ΄μ λΉ μμμ μ±μ |
grid
grid-template-xxxκ³Ό grid-auto-xxxμ λ¨μΆ μμ±
align-content
Grid 컨ν
μΈ μ μμ§ μ λ ¬ λ°©μμ μ§μ νλ μμ±
μμ±κ° | μλ―Έ |
normal | stretchμ κ°μ΅λλ€. |
start | μμμ (μμͺ½) μ λ ¬ |
center | μμ§ κ°μ΄λ° μ λ ¬ |
end | λμ (μλμͺ½) μ λ ¬ |
space-around | κ° ν μμλμ μ¬λ°±μ κ³ λ₯΄κ² μ λ ¬ |
space-between | 첫 νμ μμμ μ, λ νμ λμ μ μ λ ¬λκ³ λλ¨Έμ§ μ¬λ°±μΌλ‘ κ³ λ₯΄κ² μ λ ¬ |
space-evenly | λͺ¨λ μ¬λ°±μ κ³ λ₯΄κ² μ λ ¬ |
stretch | μ΄ μΆμ μ±μ°κΈ° μν΄ κ·Έλ¦¬λ μ½ν
μΈ λ₯Ό λλ¦Ό |
justify-content
Grid 컨ν
μΈ μ μν μ λ ¬ λ°©μμ μ§μ νλ μμ±
μμ±κ° | μλ―Έ |
normal | stretchμ κ°μ΅λλ€. |
start | μμμ (μΌμͺ½) μ λ ¬ |
center | μν κ°μ΄λ° μ λ ¬ |
end | λμ (μ€λ₯Έμͺ½) μ λ ¬ |
space-around | κ° μ΄ μ’μ°μ μ¬λ°±μ κ³ λ₯΄κ² μ λ ¬ |
space-between | 첫 μ΄μ μμμ μ, λ μ΄μ λμ μ μ λ ¬λκ³ λλ¨Έμ§ μ¬λ°±μΌλ‘ κ³ λ₯΄κ² μ λ ¬ |
space-evenly | λͺ¨λ μ¬λ°±μ κ³ λ₯΄κ² μ λ ¬ |
stretch | ν μΆμ μ±μ°κΈ° μν΄ κ·Έλ¦¬λ μ½ν
μΈ λ₯Ό λλ¦Ό |
place-content
align-content μ justify-content μ λ¨μΆ μμ±
align-items
Grid μμ΄ν
λ€μ μμ§ μ λ ¬ λ°©μμ μ§μ νλ μμ±
μμ±κ° | μλ―Έ |
normal | stretchμ κ°μ΅λλ€. |
start | μμμ (μμͺ½) μ λ ¬ |
center | μμ§ κ°μ΄λ° μ λ ¬ |
end | λμ (μλμͺ½) μ λ ¬ |
stretch | μ΄ μΆμ μ±μ°κΈ° μν΄ κ·Έλ¦¬λ μμ΄ν
μ λλ¦Ό |
normal | stretchμ κ°μ΅λλ€. |
justify-items
Grid μμ΄ν
λ€μ μν μ λ ¬ λ°©μμ μ§μ νλ μμ±
μμ±κ° | μλ―Έ |
normal | stretchμ κ°μ΅λλ€. |
start | μμμ (μΌμͺ½) μ λ ¬ |
center | μν κ°μ΄λ° μ λ ¬ |
end | λμ (μ€λ₯Έμͺ½) μ λ ¬ |
stretch | ν μΆμ μ±μ°κΈ° μν΄ κ·Έλ¦¬λ μμ΄ν
μ λλ¦Ό |
place-items
align-items μ justify-items μ λ¨μΆ μμ±
Grid Item μ μ£Όμ μμ±
Grid Container λ΄λΆμ λ΄κΈ΄ μμλ€μ κ°λ³μ μΈ μ λ ¬ λ° λ°°μΉ λ°©λ²μ μ§μ νλ μμ±
μμ± | μ€λͺ
|
grid-row-start | 그리λ μμ΄ν
(Item)μ ν μμ μμΉ μ§μ |
grid-row-end | 그리λ μμ΄ν
μ ν λ μμΉ μ§μ |
grid-row | grid-row-xxxμ λ¨μΆ μμ±(ν μμ/λ μμΉ) |
grid-column-start | 그리λ μμ΄ν
μ μ΄ μμ μμΉ μ§μ |
grid-column-end | 그리λ μμ΄ν
μ μ΄ λ μμΉ μ§μ |
grid-column | grid-column-xxxμ λ¨μΆ μμ±(μ΄ μμ/λ μμΉ) |
μμ± | μ€λͺ
|
grid-area | μμ(Area) μ΄λ¦μ μ€μ νκ±°λ,Β grid-rowμΒ grid-columnμ λ¨μΆ μμ± |
align-self | λ¨μΌ 그리λ μμ΄ν
μ μμ§(μ΄ μΆ) μ λ ¬ |
justify-self | λ¨μΌ 그리λ μμ΄ν
μ μν(ν μΆ) μ λ ¬ |
place-self | align-selfμΒ justify-selfμ λ¨μΆ μμ± |
order | 그리λ μμ΄ν
μ λ°°μΉ μμλ₯Ό μ§μ |
z-index | μμ΄ν
μ΄ μμ΄λ μμλ₯Ό μ§μ νλ μμ± |
grid-row
그리λ μμ΄ν
μμ§ λΌμΈμ μμ/λ μμΉλ₯Ό μ§μ νλ μμ±
span : νμ₯ν λΌμΈμ κ°μλ₯Ό μ§μ νλ ν€μλ
grid-column
그리λ μμ΄ν
μν λΌμΈμ μμ/λ μμΉλ₯Ό μ§μ νλ μμ±
span : νμ₯ν λΌμΈμ κ°μλ₯Ό μ§μ νλ ν€μλ
grid-area
grid-rowμΒ grid-columnμ λ¨μΆ μμ±
grid-template-areasκ° μ°Έμ‘°ν μμ μ΄λ¦μ μ§μ νλ μμ±
align-self
λ¨μΌ 그리λ μμ΄ν
(Item)μ μμ§(μ΄ μΆ) μ λ ¬νλ μμ±
μμ±κ° | μ€λͺ
|
normal | (=stretch) |
start | μμμ (μμͺ½) μ λ ¬ |
center | μμ§ κ°μ΄λ° μ λ ¬ |
end | λμ (μλμͺ½) μ λ ¬ |
stretch | μ΄ μΆμ μ±μ°κΈ° μν΄ κ·Έλ¦¬λ μμ΄ν
μ λλ¦Ό |
justify-self
λ¨μΌ 그리λ μμ΄ν
(Item)μ μν(ν μΆ) μ λ ¬νλ μμ±
μμ±κ° | μ€λͺ
|
normal | stretchμ κ°μ΅λλ€. |
start | μμμ (μΌμͺ½) μ λ ¬ |
center | μν κ°μ΄λ° μ λ ¬ |
end | λμ (μ€λ₯Έμͺ½) μ λ ¬ |
stretch | ν μΆμ μ±μ°κΈ° μν΄ κ·Έλ¦¬λ μμ΄ν
μ λλ¦Ό |
place-self
align-selfμ justify-selfμ λ¨μΆ μμ±
μμ± | μ€λͺ
|
normal | stretchμ κ°μ΅λλ€. |
start | μμμ (μΌμͺ½) μ λ ¬ |
center | μν κ°μ΄λ° μ λ ¬ |
end | λμ (μ€λ₯Έμͺ½) μ λ ¬ |
stretch | ν μΆμ μ±μ°κΈ° μν΄ κ·Έλ¦¬λ μμ΄ν
μ λλ¦Ό |
order
그리λ μμ΄ν
μ΄ μλ λ°°μΉλλ μμλ₯Ό μ§μ νλ μμ±
z-index
μμ΄ν
μ΄ μμ΄λ μμλ₯Ό μ§μ νλ μμ±
μ€μ΅μμ
1.
Grid Conrainer
2.
Grid Item
Grid Conrainer
β’
HTML
β’
CSS
β’
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>grid</title>
<link rel="stylesheet" href="css/grid.css">
</head>
<body>
<div class="container">
<h2>grid default</h2>
<div class="grid-container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<!-- grid-template-rows -->
<h2>grid-template-rows: 100px 200px 300px;</h2>
<div class="grid-container rows-px">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<h2>grid-template-rows: 1fr 2fr 1fr;</h2>
<div class="grid-container rows-fr">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<h2>grid-template-rows: 1fr 2fr 100px;</h2>
<div class="grid-container rows-mix">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<h2>grid-template-rows: [row1] 100px;</h2>
<div class="grid-container rows-name">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<h2>grid-template-rows: repeat(3, 200px)</h2>
<div class="grid-container rows-repeat">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<!-- grid-template-columns -->
<h2>grid-template-columns: 100px 200px 300px;</h2>
<div class="grid-container columns-px">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<h2>grid-template-columns: 1fr 2fr 1fr;</h2>
<div class="grid-container columns-fr">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<h2>grid-template-columns: 1fr 2fr 100px;</h2>
<div class="grid-container columns-mix">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<h2>grid-template-columns: [row1] 100px;</h2>
<div class="grid-container columns-name">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<h2>grid-template-columns: repeat(3, 200px)</h2>
<div class="grid-container columns-repeat">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<!-- grid-template-areas -->
<h2>grid-template-areas</h2>
<div class="grid-container grid-template-areas">
<div class="item grid-header">HEADER</div>
<div class="item grid-aside">ASIDE</div>
<div class="item grid-main">MAIN</div>
<div class="item grid-footer">FOOTER</div>
</div>
<!-- grid-template -->
<h2>grid-template</h2>
<div class="grid-container grid-template">
<div class="item grid-header">HEADER</div>
<!-- <div class="item grid-aside">ASIDE</div> -->
<div class="item grid-main">MAIN</div>
<div class="item grid-footer">FOOTER</div>
</div>
<!-- row-gap -->
<h2>row-gap</h2>
<div class="grid-container grid-template row-gap">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<!-- column-gap -->
<h2>column-gap</h2>
<div class="grid-container grid-template column-gap">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<!-- gap -->
<h2>gap</h2>
<div class="grid-container grid-template gap">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<!-- grid-auto-rows -->
<h2>grid-auto-rows</h2>
<div class="grid-container rows-repeat columns-repeat auto-rows">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
</div>
<!-- grid-auto-columns -->
<h2>grid-auto-columns</h2>
<div class="grid-container rows-repeat columns-repeat auto-columns">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
<div class="item auto-item">+</div>
</div>
<!-- grid-auto-flow -->
<h2>grid-auto-flow : row;</h2>
<div class="grid-container rows-repeat columns-repeat auto-flow-row">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item auto-item">+1</div>
<div class="item auto-item">+2</div>
<div class="item auto-item">+3</div>
<div class="item auto-item">+4</div>
<div class="item auto-item">+5</div>
<div class="item auto-item">+6</div>
</div>
<!-- grid-auto-flow -->
<h2>grid-auto-flow : column;</h2>
<div class="grid-container rows-repeat columns-repeat auto-flow-column">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item auto-item">+1</div>
<div class="item auto-item">+2</div>
<div class="item auto-item">+3</div>
<div class="item auto-item">+4</div>
<div class="item auto-item">+5</div>
<div class="item auto-item">+6</div>
</div>
<!-- grid -->
<!-- grid : grid-template-rows / grid-template-columns -->
<h2>grid : grid-template-rows / grid-template-columns</h2>
<div class="grid-container grid-rows-columns">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
<h2>grid : grid-template</h2>
<div class="grid-container grid-grid-template">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<!-- align-content -->
<h2>align-content : start;</h2>
<div class="grid-container rows-repeat columns-repeat align align-start">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>align-content : end;</h2>
<div class="grid-container rows-repeat columns-repeat align align-end">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>align-content : center;</h2>
<div class="grid-container rows-repeat columns-repeat align align-center">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>align-content : space-between;</h2>
<div class="grid-container rows-repeat columns-repeat align align-between">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>align-content : space-around;</h2>
<div class="grid-container rows-repeat columns-repeat align align-around">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>align-content : space-evenly;</h2>
<div class="grid-container rows-repeat columns-repeat align align-evenly">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">+</div>
<div class="item">+</div>
<div class="item">+</div>
</div>
<h2>align-content : stretch;</h2>
<div class="grid-container rows-repeat columns-repeat align align-stretch">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">stretch</div>
<div class="item">stretch</div>
<div class="item">stretch</div>
</div>
<!-- justify-content -->
<h2>justify-content : start;</h2>
<div class="grid-container rows-repeat columns-repeat justify justify-start">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>justify-content : end;</h2>
<div class="grid-container rows-repeat columns-repeat justify justify-end">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>justify-content : center;</h2>
<div class="grid-container rows-repeat columns-repeat justify justify-center">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>justify-content : space-between;</h2>
<div class="grid-container rows-repeat columns-repeat justify justify-between">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>justify-content : space-around;</h2>
<div class="grid-container rows-repeat columns-repeat justify justify-around">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<h2>justify-content : space-evenly;</h2>
<div class="grid-container rows-repeat columns-repeat justify justify-evenly">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">+</div>
<div class="item">+</div>
<div class="item">+</div>
</div>
<h2>justify-content : stretch;</h2>
<div class="grid-container rows-repeat columns-repeat justify justify-stretch">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">stretch</div>
<div class="item">stretch</div>
<div class="item">stretch</div>
</div>
<!-- place-content -->
<h2>place-content: center center;</h2>
<div class="grid-container rows-repeat columns-repeat place place-center-center">
<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 class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<!-- align-items -->
<h2>align-items: start;</h2>
<div class="grid-container rows-repeat columns-repeat align-items-start">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
<h2>align-items: end;</h2>
<div class="grid-container rows-repeat columns-repeat align-items-end">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
<h2>align-items: center;</h2>
<div class="grid-container rows-repeat columns-repeat align-items-center">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
<h2>align-items: stretch;</h2>
<div class="grid-container rows-repeat columns-repeat align-items-stretch">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
<!-- justify-items -->
<h2>justify-items: start;</h2>
<div class="grid-container rows-repeat columns-repeat justify-items-start">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
<h2>justify-items: end;</h2>
<div class="grid-container rows-repeat columns-repeat justify-items-end">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
<h2>justify-items: center;</h2>
<div class="grid-container rows-repeat columns-repeat justify-items-center">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
<h2>justify-items: stretch;</h2>
<div class="grid-container rows-repeat columns-repeat justify-items-stretch">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
<!-- place-items : center center -->
<h2>place-items: center center;</h2>
<div class="grid-container rows-repeat columns-repeat place-items-center">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
</div>
</body>
</html>
HTML
볡μ¬
β’
CSS
.container {
width: 1200px;
margin: 0 auto;
border: 3px dashed hotpink;
margin-bottom: 500px;
padding-bottom: 500px;
}
/* grid */
.grid-container {
display: grid;
border: 1px solid lightcoral;
}
.item {
width: calc(100%-20px);
height: calc(100%-20px);
margin: 20px;
padding: 20px;
font-size: 30px;
text-align: center;
line-height: 1;
background-color: cornflowerblue;
color: white;
box-sizing: border-box;
}
/* grid-template-rows */
.rows-px { grid-template-rows: 100px 200px 300px;}
.rows-fr { grid-template-rows: 1fr 2fr 1fr;}
.rows-mix { grid-template-rows: 1fr 2fr 100px;}
.rows-name { grid-template-rows: [row1] 100px [row2] 150px [row3] 200px;}
.rows-repeat { grid-template-rows: repeat(3, 200px); }
/* grid-template-columns */
.columns-px { grid-template-columns: 100px 200px 300px;}
.columns-fr { grid-template-columns: 1fr 2fr 1fr;}
.columns-mix { grid-template-columns: 1fr 2fr 100px;}
.columns-name { grid-template-columns: [row1] 100px [row2] 150px [row3] 200px;}
.columns-repeat { grid-template-columns: repeat(3, 200px); }
/* grid-template-areas */
/* grid-area : μμμ μ΄λ¦μ μ§μ νλ μμ± */
.grid-header { grid-area: header; }
.grid-aside { grid-area: aside; }
.grid-main { grid-area: main; }
.grid-footer { grid-area: footer; }
.grid-template-areas {
grid-template-areas:
"header header header"
"aside main main"
"footer footer footer";
}
/* grid-template */
.grid-template {
grid-template:
"header header header" 100px
"main main main" 200px
"footer footer footer" 150px
/ 100px 200px 300px
;
}
/* gap */
.row-gap { row-gap: 100px; }
.column-gap { column-gap: 200px; }
.gap { gap: 100px 200px; }
/* auto */
.auto-rows { grid-auto-rows: 300px; }
.auto-columns { grid-auto-columns: 300px; }
.auto-item { background-color: mediumslateblue; }
/* grid column */
/* 3n-2 : 1, 4, 7, ... */
/* 3n-1 : 2, 5, 8, ... */
/* 3n : 3, 6, 9, ... */
.auto-columns .item:nth-child(3n-2) { grid-column: 1/2; }
.auto-columns .item:nth-child(3n-1) { grid-column: 2/3; }
.auto-columns .item:nth-child(3) { grid-column: 3/4; }
.auto-columns .auto-item:nth-child(3n-2) { grid-column: 4/5; grid-row: 1/2; }
.auto-columns .auto-item:nth-child(3n-1) { grid-column: 4/5; grid-row: 2/3; }
.auto-columns .auto-item:nth-child(3) { grid-column: 4/5; grid-row: 3/4; }
/* grid-auto-flow */
.auto-flow-row { grid-auto-flow: row; }
.auto-flow-column { grid-auto-flow: column; }
/* grid */
/* [grid-template-rows] [grid-template-column] */
.grid-rows-columns {
grid: 100px 200px / 1fr 3fr;
/* grid-template-rows: 100px 200px; */
/* grid-template-columns: 1fr 3fr; */
}
.grid-grid-template {
grid:
"header header header" 100px
"main main main" 200px
"footer footer footer" 150px
/ 200px 300px 400px;
}
/* align-content */
.align { height: 1000px; }
.align-start { align-content: start; }
.align-end { align-content: end; }
.align-center { align-content: center; }
.align-between { align-content: space-between; }
.align-around { align-content: space-around; }
.align-evenly { align-content: space-evenly; }
.align-stretch { align-content: stretch; }
/* justify-content */
.justify { grid-auto-flow: column; }
.justify-start { justify-content: start; }
.justify-end { justify-content: end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }
.justify-evenly { justify-content: space-evenly; }
.justify-stretch { justify-content: stretch; }
/* place-content */
.place { height: 1000px; }
.place-center-center {
place-content: center center;
/* align-content justify-content */
/* 컨ν
μΈ μμ§μ λ ¬ 컨ν
μΈ μνμ λ ¬ */
}
/* items */
.items {
width: 50px;
height: 50px;
margin: 20px;
font-size: 30px;
text-align: center;
line-height: 50px;
background-color: cornflowerblue;
color: white;
box-sizing: border-box;
}
/* align-items */
.align-items-start { align-items: start; }
.align-items-end { align-items: end; }
.align-items-center { align-items: center; }
.align-items-stretch { align-items: stretch; }
.align-items-stretch .items { height: auto; }
/* justify-items */
.justify-items-start { justify-items: start; }
.justify-items-end { justify-items: end; }
.justify-items-center { justify-items: center; }
.justify-items-stretch { justify-items: stretch; }
.justify-items-stretch .items { width: auto; }
/* place-items */
.place-items-center {
place-items: center center;
/* align-items justify-items */
/* μμ΄ν
μμ§μ λ ¬ μμ΄ν
μνμ λ ¬ */
}
CSS
볡μ¬
Grid Item
β’
HTML
β’
CSS
β’
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grid Item</title>
<link rel="stylesheet" href="css/grid-item.css">
</head>
<body>
<div class="container">
<h2>grid-row</h2>
<div class="grid-container grid-row">
<div class="item item1">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
</div>
<h2>grid-column</h2>
<div class="grid-container grid-column">
<div class="item item1">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
</div>
<h2>grid-area</h2>
<div class="grid-container grid-area">
<div class="item item1">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
<h2>grid-area-name</h2>
<div class="grid-container grid-area-name">
<div class="item header">header</div>
<div class="item aside">aside</div>
<div class="item main">main</div>
<div class="item footer">footer</div>
</div>
<h2>align-self</h2>
<div class="grid-container align-self">
<div class="item align-start"></div>
<div class="item align-center"></div>
<div class="item align-end"></div>
<div class="item align-stretch"></div>
</div>
<h2>justify-self</h2>
<div class="grid-container justify-self">
<div class="item justify-start"></div>
<div class="item justify-center"></div>
<div class="item justify-end"></div>
<div class="item justify-stretch"></div>
</div>
<h2>place-self</h2>
<div class="grid-container place-self">
<div class="item place-center"></div>
</div>
<h2>order</h2>
<div class="grid-container order">
<div class="item order5">1</div>
<div class="item order3">2</div>
<div class="item order-1">3</div>
<div class="item order2">4</div>
<div class="item order1">5</div>
</div>
<h2>z-index</h2>
<div class="grid-container z-index">
<div class="item z-index">1</div>
<div class="item z-index">2</div>
<div class="item z-index">3</div>
</div>
</div>
</body>
</html>
HTML
볡μ¬
β’
CSS
.container {
width: 1200px;
margin: 0 auto;
border: 3px dashed coral;
margin-bottom: 500px;
padding-bottom: 500px;
}
.grid-container {
display: grid;
border: 1px solid lightcoral;
}
.item {
width: calc(100%-20px);
height: calc(100%-20px);
margin: 20px;
padding: 20px;
font-size: 30px;
text-align: center;
background-color: cornflowerblue;
color: white;
box-sizing: border-box;
}
.grid-row {
grid-template-columns: auto auto auto auto;
gap: 10px;
padding: 10px;
}
/* item μμ± : grid-row */
.grid-row .item1 {
grid-row: 1 / span 2; /* span : νμ₯ν λΌμΈ κ°μ μ§μ */
/* grid-row: 1 / 3; */ /* λ¨μΆμμ± : grid-row-start / grid-row-end */
/* grid-row-start: 1; */ /* κ°λ³μμ± */
/* grid-row-end: 3; */ /* κ°λ³μμ± */
}
.grid-column {
grid-template-columns: auto auto auto auto;
gap: 10px;
padding: 10px;
}
/* item μμ± : grid-column */
.grid-column .item1 {
grid-column: 1 / span 2; /* span : νμ₯ν λΌμΈ κ°μ μ§μ */
/* grid-column: 1 / 3; */ /* λ¨μΆμμ± : grid-column-start / grid-column-end */
/* grid-column-start: 1; */ /* κ°λ³μμ± */
/* grid-column-end: 3; */ /* κ°λ³μμ± */
}
.grid-area {
grid-template-columns: repeat(4, auto);
gap: 10px;
padding: 10px;
}
/* item μμ± : grid-area
- (grid-row, grid-column λ¨μΆ)
*/
.grid-area .item1 {
/* row-start / column-start / row-end / column-end */
grid-area: 1 / 1 / 3 / 3;
/*
grid-row : 1 / 3;
grid-row-start : 1;
grid-row-end : 3;
grid-column : 1 / 3;
grid-column-start : 1;
grid-column-end : 3;
*/
}
/* item μμ± : grid-area - μμμ΄λ¦ μ§μ */
.grid-area-name .header { grid-area: header; }
.grid-area-name .aside { grid-area: aside; }
.grid-area-name .main { grid-area: main; }
.grid-area-name .footer { grid-area: footer; }
.grid-area-name {
grid-template-areas:
/* λ°°μΉλ Grid μμ΄ν
μ μμμ΄λ¦ μ§μ */
/* 1μ΄ 2μ΄ 3μ΄ 4μ΄ */
'header header header header' /* 1ν */
'aside aside main main' /* 2ν */
'footer footer footer footer' /* 3ν */
;
}
/* item μμ± - align-self */
.align-self {
grid-template-columns: auto auto;
grid-template-rows: 200px 200px;
}
.align-self .item {
width: 50px;
height: 50px;
padding: 5px;
}
.align-self .align-start { align-self: start;}
.align-self .align-center { align-self: center;}
.align-self .align-end { align-self: end;}
.align-self .align-stretch { align-self: stretch; height: auto;}
/* item μμ± - justify-self */
.justify-self {
grid-template-columns: auto auto;
grid-template-rows: 200px 200px;
}
.justify-self .item {
width: 50px;
height: 50px;
padding: 5px;
}
.justify-self .justify-start { justify-self: start; }
.justify-self .justify-center { justify-self: center; }
.justify-self .justify-end { justify-self: end; }
.justify-self .justify-stretch { justify-self: stretch; width: auto; }
/* item μμ± - place-self */
.place-self {
grid-template-columns: auto ;
grid-template-rows: 300px ;
}
.place-self .item {
width: 50px;
height: 50px;
padding: 5px;
}
.place-self .place-center {
place-self: center center;
/* align-self justify-self */
}
.order {
grid-template-rows: repeat(2, 1fr);
grid-template-columns: repeat(3, 1fr);
}
.order .order-1 { order: -1;}
.order .order1 { order: 1;}
.order .order2 { order: 2;}
.order .order3 { order: 3;}
.order .order5 { order: 5;}
.z-index {
grid-template-rows: repeat(2, 1fr);
grid-template-columns: repeat(3, 1fr);
}
.z-index .item:nth-child(1) {
grid-row: 1 / 2;
grid-column: 1 / 3;
z-index: 2;
}
.z-index .item:nth-child(2) {
grid-row: 1 / 3;
grid-column: 2 / 3;
background-color: lightcoral;
z-index: 1;
}
.z-index .item:nth-child(3) {
grid-row: 2 / 3;
grid-column: 2 / 4;
background-color: mediumseagreen;
}
CSS
볡μ¬
Quiz
βμμ μΈμβ. βμ λ
Όμ λ¬ΌλκΈ°β λΌλ λ§μ μμλμ? λΉκ·Όμ λ¬Όμ£ΌκΈ°λ₯Ό ν΄λ³΄κ² μ΅λλ€.