본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

CSS Grid

원문 보기 위키 갱신

그리드 컬럼, 내비게이션, 컴포넌트 등의 레이아웃·정렬·크기를 반응형 그리드 유틸리티 한 세트로 빠르게 관리할 수 있어요.

출처: 문서

본문

grid가 처음이거나 익숙하지 않다면, 이 CSS-Tricks grid 가이드를 읽어 보는 걸 권해요.

부모(parent)용 프로퍼티

display

grid 컨테이너를 정의하려면 display CSS 프로퍼티를 grid 또는 inline-grid 중 하나의 값으로 지정해야 해요.


<Box sx={{ display: 'grid' }}>…</Box>
<Box sx={{ display: 'inline-grid' }}>…</Box>

grid-template-rows

grid-template-rows 프로퍼티는 그리드 행(row)의 라인 이름과 트랙 크기 함수를 정의해요.


grid-template-columns

grid-template-columns 프로퍼티는 그리드 컬럼의 라인 이름과 트랙 크기 함수를 정의해요.


gap

gap: size 프로퍼티는 CSS grid 안의 서로 다른 아이템 사이의 간격을 지정해요.


row-gap & column-gap

row-gap과 column-gap CSS 프로퍼티는 행(row)과 컬럼(column) 간격을 각각 독립적으로 지정할 수 있게 해 줘요.


grid-template-areas

grid-template-area 프로퍼티는 grid-area 프로퍼티로 지정된 그리드 영역의 이름을 참조해서 그리드 템플릿을 정의해요.


grid-auto-columns

grid-auto-column 프로퍼티는 암시적으로 생성된 그리드 컬럼 트랙 또는 트랙 패턴의 크기를 지정해요.


위 데모에서, 두 번째(보이지 않는) 컬럼은 1fr/4의 너비를 갖는데 대략 25%와 같아요.

grid-auto-rows

grid-auto-rows 프로퍼티는 암시적으로 생성된 그리드 행(row) 트랙 또는 트랙 패턴의 크기를 지정해요.


grid-auto-flow

grid-auto-flow 프로퍼티는 자동 배치(placement) 알고리즘이 어떻게 동작하는지 제어해서, 자동 배치된 아이템이 그리드에 어떻게 흘러 들어가는지 정확히 지정해요.


자식(children)용 프로퍼티

grid-column

grid-column 프로퍼티는 grid-column-start + grid-column-end의 shorthand예요. grid-auto-columns 예시에서 어떻게 쓰이는지 볼 수 있어요.

시작과 끝 라인을 설정할 수 있어요.

<Box sx={{ gridColumn: '1 / 3' }}>…

또는 넘을(span) 컬럼 수를 설정할 수 있어요.

<Box sx={{ gridColumn: 'span 2' }}>…

grid-row

grid-row 프로퍼티는 grid-row-start + grid-row-end의 shorthand예요. grid-auto-rows 예시에서 어떻게 쓰이는지 볼 수 있어요.

시작과 끝 라인을 설정할 수 있어요.

<Box sx={{ gridRow: '1 / 3' }}>…

또는 넘을(span) 행(row) 수를 설정할 수 있어요.

<Box sx={{ gridRow: 'span 2' }}>…

grid-area

grid-area 프로퍼티로 아이템에 이름을 줄 수 있고, 그러면 grid-template-areas 프로퍼티로 만든 템플릿에서 그 이름을 참조할 수 있어요. grid-template-area 예시에서 어떻게 쓰이는지 볼 수 있어요.

<Box sx={{ gridArea: 'header' }}>…

API

import { grid } from '@mui/system';
Import name Prop CSS property Theme key
gap gap gap none
columnGap columnGap column-gap none
rowGap rowGap row-gap none
gridColumn gridColumn grid-column none
gridRow gridRow grid-row none
gridAutoFlow gridAutoFlow grid-auto-flow none
gridAutoColumns gridAutoColumns grid-auto-columns none
gridAutoRows gridAutoRows grid-auto-rows none
gridTemplateColumns gridTemplateColumns grid-template-columns none
gridTemplateRows gridTemplateRows grid-template-rows none
gridTemplateAreas gridTemplateAreas grid-template-areas none
gridArea gridArea grid-area none

더 알아보기 (Learn more)