grid

grid CSS 속성은 shorthand property 입니다. 외재적인 속성인 (grid-template-rows, grid-template-columns, grid-template-areas), 값과 내재적인 속성인 (grid-auto-rows, grid-auto-columns, grid-auto-flow), 값을 한번에 설정합니다.

Note: You can only specify the explicit or the implicit grid properties in a single grid declaration. The sub-properties you don’t specify are set to their initial value, as normal for shorthands. Also, the gutter properties are NOT reset by this shorthand.

Syntax

/* <'grid-template'> values */
grid: none;
grid: "a" 100px "b" 1fr;
grid: [linename1] "a" 100px [linename2];
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'>? values */
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'> values */
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);

/* Global values */
grid: inherit;
grid: initial;
grid: unset;

Values

<'grid-template'>
grid-template-columns, grid-template-rows, grid-template-areas 값을 내포하고 있는 grid-template의 값을 정의합니다.
<'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?
grid-template-rows (and the grid-template-columns property to none)은 auto-flow 값을 설정합니다. grid-auto-columns (and setting grid-auto-rows to auto)은 auto-repeat를 설정합니다. grid-auto-flow 또한 마찬가지로 auto-repeat에 영향을 줍니다. 만약 이 값이 생략되었다면 그 기본값은 dense 입니다.

만약 grid 의 sub-properties가 있다면, 해당 값으로 초기화 됩니다.

[ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>
grid-template-columns (and the grid-template-rows property to none)은 auto-flow 값을 설정합니다. grid-auto-rows (and setting grid-auto-columns to auto)은 열(row)에 대한 auto-repeat를 설정합니다. grid-auto-flow 또한 마찬가지로 auto-repeat에 영향을 줍니다. 만약 이 값이 생략되었다면 그 기본값은 dense 입니다.

만약  grid 의 sub-properties가 있다면, 해당 값으로 초기화 됩니다.

Formal syntax

Example

HTML Content

<div id="container">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>

CSS Content

#container {
  display: grid;
  grid: repeat(2, 60px) / auto-flow 80px;
}

#container > div {
  background-color: #8ca0ff;
  width: 50px;
  height: 50px;
}

Result

Specifications

Specification Status Comment
CSS Grid Layout
The definition of 'grid' in that specification.
Candidate Recommendation Initial definition
초기값as each of the properties of the shorthand:
적용대상grid containers
상속no
Percentagesas each of the properties of the shorthand:
Computed valueas each of the properties of the shorthand:
  • grid-template-rows: as specified, but with relative lengths converted into absolute lengths
  • grid-template-columns: as specified, but with relative lengths converted into absolute lengths
  • grid-template-areas: as specified
  • grid-auto-rows: the percentage as specified or the absolute length
  • grid-auto-columns: the percentage as specified or the absolute length
  • grid-auto-flow: as specified
  • grid-column-gap: the percentage as specified or the absolute length
  • grid-row-gap: the percentage as specified or the absolute length
  • column-gap: as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements
  • row-gap: as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements
Animation typediscrete

Browser compatibility

BCD tables only load in the browser

See also