Search

GRID λ ˆμ΄μ•„μ›ƒ

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

β€œμ•„μ „μΈμˆ˜β€. β€œμ œ λ…Όμ˜ λ¬ΌλŒ€κΈ°β€ λΌλŠ” 말을 μ•„μ‹œλ‚˜μš”? 당근에 λ¬Όμ£ΌκΈ°λ₯Ό ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.