[2023.03.08] 12. display: grid

2023. 3. 8. 17:57ㆍDev./CSS

πŸ” display 속성 쀑 grid에 λŒ€ν•΄ 정리.

 

grid

μžμ‹ μš”μ†Œλ“€μ΄ μ»¨ν…Œμ΄λ„ˆ μ•ˆ 곡간을 λ§žμΆ”κΈ° μœ„ν•΄ 크기λ₯Ό ν‚€μš°κ±°λ‚˜ μ€„μ΄λŠ” 방법

λΆ€λͺ¨μš”μ†Œλ₯Ό grid-container μžμ‹μš”μ†Œλ₯Ό grid-item

μ›ΉνŽ˜μ΄μ§€λ₯Ό μœ„ν•œ 2차원 λ ˆμ΄μ•„μ›ƒ(xμΆ•, yμΆ•) μ‹œμŠ€ν…œ

 

[좜처 : μœ„λ‹ˆλΈŒ(Weniv)]

 

 

grid-container 속성

μ•„λž˜μ˜ 속성듀은 grid-container(λΆ€λͺ¨ μš”μ†Œ)μ—μ„œ μ‚¬μš©λ˜λŠ” 속성이닀.

 

grid-template-columns

  • μ—΄λ°©ν–₯ κ·Έλ¦¬λ“œ νŠΈλž™μ˜ μ‚¬μ΄μ¦ˆ μ„€μ •

 

grid-template-rows

  • ν–‰λ°©ν–₯ κ·Έλ¦¬λ“œ νŠΈλž™μ˜ μ‚¬μ΄μ¦ˆ μ„€μ •

πŸ’‘μƒˆλ‘œμš΄ λ‹¨μœ„ fr

  • fraction: λΆ„μˆ˜ 
  • μ»¨ν…Œμ΄λ„ˆλ₯Ό λΆ„ν•  
  • grid μ»¨ν…Œμ΄λ„ˆ μ•ˆμ—μ„œ νŠΈλž™μ˜ λΉ„μœ¨μ„ μ§€μ •ν•΄μ£ΌλŠ” μœ μ—°ν•œ 길이 λ‹¨μœ„
  • 1fr 1fr 1fr은 1:1:1 의 λΉ„μœ¨μ„ μ˜λ―Έν•¨

 

grid-template-areas

[좜처 : μœ„λ‹ˆλΈŒ(Weniv)]

 

κ·Έλ¦¬λ“œ 에어리어λ₯Ό μ„€μ •ν•¨μœΌλ‘œμ¨ μ•„μ΄ν…œλ“€μ΄ κ°€μ§€λŠ” 곡간을 ν•©μΉ˜κ±°λ‚˜ λ‚˜λˆŒ 수 μžˆλ‹€.

See the Pen Untitled by astinaus (@astinaus) on CodePen.

 

 

 

 

ν•¨μˆ˜

  • repeat()
    • row ν˜Ήμ€ column λ°©ν–₯으둜 κ·Έλ¦¬λ“œ νŠΈλž™μ˜ μ‚¬μ΄μ¦ˆλ₯Ό μ’€ 더 κ°„λ‹¨ν•œ ν˜•νƒœλ‘œ ν‘œν˜„ν•˜λ„λ‘ λ„μ™€μ£ΌλŠ” ν•¨μˆ˜.
    • ν•¨μˆ˜μ— μ „λ‹¬ν•˜λŠ” 첫번째 μΈμžλŠ” 반볡 횟수, λ‘λ²ˆμ§Έ μΈμžλŠ” λ°˜λ³΅ν•  κ°’.
  • minmax()
    • κ·Έλ¦¬λ“œμ—μ„œ μ΅œμ†Œμ™€ μ΅œλŒ€ μ‚¬μ΄μ˜ λ²”μœ„λ₯Ό μ„€μ •.
    • μ΅œμ†Ÿκ°’κ³Ό μ΅œλŒ“κ°’μ„ μ˜λ―Έν•˜λŠ” 두가지 인자λ₯Ό 가짐.
    • min보닀 ν¬κ±°λ‚˜ κ°™κ³ , max보닀 μž‘κ±°λ‚˜ 같은 크기 λ²”μœ„λ₯Ό μ •μ˜.

 

 

auto-fill & auto-fit

  • repeat ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•  λ•Œ, λ°˜λ³΅λ˜λŠ” 카운트λ₯Ό κ³ μ •ν•˜μ§€ μ•Šκ³  μ»¨ν…Œμ΄λ„ˆμ˜ 넓이에 따라
    κ°€λŠ₯ν•œ λ§Žμ€ κ·Έλ¦¬λ“œ μ»¬λŸΌμ„ λ°°μΉ˜ν•˜κ³  μ‹Άλ‹€λ©΄ μ‚¬μš©ν•˜λŠ” ν‚€μ›Œλ“œ κ°’.
  • auto-fill: κ°€λŠ₯ν•œ λ§Žμ€ 셀듀을 λ§Œλ“¦. 빈 곡간이 생김
  • auto-fit: κ·Έλ¦¬λ“œ μ»¨ν…Œμ΄λ„ˆ 내뢀에 곡간이 남을 경우, κ·Έ 곡간을 각 셀듀이 λ‚˜λˆ κ°€μ§.

 

gap

μ…€κ³Ό μ…€ μ‚¬μ΄μ˜ 간격 μ„€μ •.

λ³΅μž‘ν•œ λ ˆμ΄μ•„μ›ƒμ—μ„œ margin λŒ€μ‹  νŽΈλ¦¬ν•˜κ²Œ 간격 μ„€μ • κ°€λŠ₯

 

 

align-content

  • κ·Έλ¦¬λ“œ μ½˜ν…μΈ μ˜ 수직(μ—΄) μ •λ ¬
  • κ·Έλ¦¬λ“œ μ½˜ν…μΈ μ˜ μ„Έλ‘œ 높이가 κ·Έλ¦¬λ“œ μ»¨ν…Œμ΄λ„ˆλ³΄λ‹€ μž‘μ•„μ•Ό 함.
  • stretch, center, start, end, space-around, space-between, space-evenly

 

justify-content

  • κ·Έλ¦¬λ“œ μ½˜ν…μΈ μ˜ μˆ˜ν‰(ν–‰) μ •λ ¬
  • κ·Έλ¦¬λ“œ μ½˜ν…μΈ μ˜ κ°€λ‘œ 높이가 κ·Έλ¦¬λ“œ μ»¨ν…Œμ΄λ„ˆλ³΄λ‹€ μž‘μ•„μ•Ό 함.
  • stretch, center, start, end, space-around, space-between, space-evenly

 

align-items

  • 직계 μžμ‹μ— λŒ€ν•œ 수직(μ—΄) 정렬을 λͺ¨λ‘ λ™μΌν•˜κ²Œ μ€€λ‹€.
  • stretch, center, start, end

 

justify-items

  • 직계 μžμ‹μ— λŒ€ν•œ μˆ˜ν‰(ν–‰) 정렬을 λͺ¨λ‘ λ™μΌν•˜κ²Œ μ€€λ‹€.
  • stretch, center, start, end

 

[좜처 : μœ„λ‹ˆλΈŒ(Weniv)]

 

 

grid-item 속성

μ•„λž˜ 속성은 grid-item(μžμ‹ μš”μ†Œ)μ—μ„œ μ‚¬μš©ν•˜λŠ” 속성

 

grid-area

grid-template-areas 와 ν•¨κ»˜ μ‚¬μš©ν•  μˆ˜λ„ 있고, μ•„μ΄ν…œμ— grid-areaλ₯Ό λ‹¨λ…μ μœΌλ‘œ μ‚¬μš©ν•  μˆ˜λ„ μžˆλ‹€.

  grid-row-start: 1; /* 1 */
  grid-row-end: 2; /* 3 */
  grid-column-start: 1; /* 2 */
  grid-column-end: 4; /* 4 */


  grid-row: 1/2;
  grid-column: 1/4;


  grid-area: 1/1/2/4;

	grid-area: 1/1/1/span 3;

πŸ’‘span

  • span의 사전적 의미: ‘ν•œ 뼘’, ‘~을 μ±„μš°λ‹€’ 
  • κ·Έλ¦¬λ“œμ—μ„œ ν–‰κ³Ό 열을 λ³‘ν•©ν• λ•Œ span ν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•œλ‹€.

 

z-index

grid μ•ˆμ—μ„œ z-index μ†μ„±μœΌλ‘œ 화면에 λ³΄μ—¬μ§€λŠ” μš°μ„ μˆœμœ„λ₯Ό μ„€μ • κ°€λŠ₯.

position 속성을 μ‚¬μš©ν•˜μ§€ μ•Šλ”λΌλ„ κ°€λŠ₯함.

 

grid

  • 단좕속성
  • grid-template-rows grid-template-columns grid-template-areas grid-auto-rows grid-auto-columns grid-auto-flow 
grid: auto-flow / 1fr 1fr 1fr;

grid: auto-flow dense / 40px 40px 1fr;