CSS grid: 그리드 레이아웃 단축 속성

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-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-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?
    • 열 방향 자동 그리드를 설정합니다. grid-template-rows 속성으로 행 트랙을 명시하고, grid-auto-columns 속성으로 암시적 열 트랙의 크기를 설정합니다. grid-auto-flow 속성 또한 column으로 설정되며, dense 키워드를 명시하면 dense도 적용됩니다.

      grid-template-columnsnone으로, grid-auto-rowsauto로 설정됩니다. 기타 구성 속성들은 초기화됩니다.

  • [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>
    • 행 방향 자동 그리드를 설정합니다. grid-template-columns 속성으로 열 트랙을 명시하고, grid-auto-rows 속성으로 암시적 행 트랙의 크기를 설정합니다. grid-auto-flow 속성 또한 row으로 설정되며, dense 키워드를 명시하면 dense도 적용됩니다.

      grid-template-rowsnone으로, grid-auto-columnsauto로 설정됩니다. 기타 구성 속성들은 초기화됩니다.

명세

브라우저 호환성

MDN browser-compat-data
데스크톱모바일
iOSAndroid
SafariChromeFirefoxSafariSafari WebViewChromeAndroid WebViewFirefoxSamsung Internet
grid

같이 보기

마지막 수정:

CC BY-SA 4.0 unless otherwise noted. See LICENSE.