CSS grid: 그리드 레이아웃 단축 속성
Baseline넓은 지원
모든 주요 브라우저가 지원하는 기능입니다.
CSS grid
단축 속성은 그리드 컨테이너의 명시적, 암시적 속성을 한 번에 설정합니다.
.grid {
grid: auto-flow / 1fr 1fr 1fr;
/* grid: auto-flow dense / 40px 40px 1fr; */
/* grid: repeat(3, 40px) / auto-flow; */
}
.grid {
width: 300px;
border: 1px solid #ccc;
color: #fff;
display: grid;
gap: 8px;
padding: 8px;
}
.item {
background: #f0f0f0;
color: #000;
display: flex;
align-items: center;
border: 1px solid #ccc;
justify-content: center;
font-size: 1.25rem;
font-weight: 700;
}
.item:nth-child(1) {
background: #24c0a5;
color: #fff;
}
.item:nth-child(2) {
background: #0043ff;
color: #fff;
grid-column: 1 / span 2;
}
.item:nth-child(3) {
background: #b42809;
color: #fff;
}
.item:nth-child(4) {
background: #ffb800;
color: #fff;
}
<div class="grid">
<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>
불러오는 중...
구성 속성
grid-auto-columns
grid-auto-flow
grid-auto-rows
grid-template-areas
grid-template-columns
grid-template-rows
구문
/* <'grid-template'> 값 */
grid: none;
grid: "a" 100px "b" 1fr;
grid: [line-name1] "a" 100px [line-name2];
grid: "a" 200px "b" min-content;
grid: "a" minmax(100px, max-content) "b" 20%;
grid: 100px / 200px;
grid: minmax(400px, min-content) / repeat(auto-fill, 50px);
/* <'grid-template-rows'> /
[ auto-flow && dense? ] <'grid-auto-columns'>? 값 */
grid: 200px / auto-flow;
grid: 30% / auto-flow dense;
grid: repeat(3, [line1 line2 line3] 200px) / auto-flow 300px;
grid: [line1] minmax(20em, max-content) / auto-flow dense 40%;
/* [ auto-flow && dense? ] <'grid-auto-rows'>? /
<'grid-template-columns'> 값 */
grid: auto-flow / 200px;
grid: auto-flow dense / 30%;
grid: auto-flow 300px / repeat(3, [line1 line2 line3] 200px);
grid: auto-flow dense 40% / [line1] minmax(20em, max-content);
/* 전역 값 */
grid: inherit;
grid: initial;
grid: revert;
grid: revert-layer;
grid: unset;
값
<'grid-template'>
- [
grid-template
]과 같습니다. 즉grid-template-areas
,grid-template-rows
,grid-template-columns
속성을 설정합니다.
- [
<'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?
-
열 방향 자동 그리드를 설정합니다.
grid-template-rows
속성으로 행 트랙을 명시하고,grid-auto-columns
속성으로 암시적 열 트랙의 크기를 설정합니다.grid-auto-flow
속성 또한column
으로 설정되며,dense
키워드를 명시하면dense
도 적용됩니다.grid-template-columns
는none
으로,grid-auto-rows
는auto
로 설정됩니다. 기타 구성 속성들은 초기화됩니다.
-
[ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>
-
행 방향 자동 그리드를 설정합니다.
grid-template-columns
속성으로 열 트랙을 명시하고,grid-auto-rows
속성으로 암시적 행 트랙의 크기를 설정합니다.grid-auto-flow
속성 또한row
으로 설정되며,dense
키워드를 명시하면dense
도 적용됩니다.grid-template-rows
는none
으로,grid-auto-columns
는auto
로 설정됩니다. 기타 구성 속성들은 초기화됩니다.
-
명세
브라우저 호환성
데스크톱 | 모바일 | ||||||||
---|---|---|---|---|---|---|---|---|---|
iOS | Android | ||||||||
Safari | Chrome | Firefox | Safari | Safari WebView | Chrome | Android WebView | Firefox | Samsung Internet | |
grid |
같이 보기
- 자동 생성 열 크기 설정:
grid-auto-columns
- 자동 배치 방향 설정:
grid-auto-flow
- 자동 생성 행 크기 설정:
grid-auto-rows
- 그리드 영역 정의:
grid-template-areas
- 그리드 열 정의:
grid-template-columns
- 그리드 행 정의:
grid-template-rows