grid
CSS の grid
プロパティは一括指定プロパティで、明示的なすべてのグリッドプロパティ (grid-template-rows
, grid-template-columns
, grid-template-areas
) と、暗黙のすべてのグリッドプロパティ (grid-auto-rows
, grid-auto-columns
, grid-auto-flow
) を単一の宣言で設定します。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
メモ: 明示的なグリッドプロパティ、または暗黙のグリッドプロパティのみを単一の grid
宣言で設定することができます。指定しないサブプロパティは、通常の一括指定と同様に初期値に設定されます。また、 gutter プロパティはこの一括指定では初期化されません。
構文
/* <'grid-template'> 値 */
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);
/* グローバル値 */
grid: inherit;
grid: initial;
grid: unset;
値
<'grid-template'>
grid-template
を定義し、これにはgrid-template-columns
,grid-template-rows
,grid-template-areas
が含まれます。<'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?
grid-template-rows
プロパティを明示的に設定 (およびgrid-template-columns
プロパティをnone
に設定) することで行トラックを設定し、grid-auto-columns
プロパティを設定 (およびgrid-auto-rows
をauto
に設定) することで列トラックの自動反復方法を設定します。dense
が設定されていれば、grid-auto-flow
もcolumn
に設定されます。ほかの
grid
のサブプロパティはすべて、初期値に初期化されます。[ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>
grid-template-columns
プロパティを明示的に設定 (およびgrid-template-rows
プロパティをnone
に設定) することで列トラックを設定し、grid-auto-rows
プロパティを設定 (およびgrid-auto-columns
をauto
に設定) することで行トラックの児童反復方法を設定します。dense
が設定されていれば、grid-auto-flow
もcolumn
に設定されます。ほかの
grid
のサブプロパティはすべて、初期値に初期化されます。
形式文法
<'grid-template'> | <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? | [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>
例
HTML
<div id="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
CSS
#container {
display: grid;
grid: repeat(2, 60px) / auto-flow 80px;
}
#container > div {
background-color: #8ca0ff;
width: 50px;
height: 50px;
}
結果
仕様書
仕様書 | 状態 | 備考 |
---|---|---|
CSS Grid Layout grid の定義 |
勧告候補 | 初回定義 |
初期値 | 一括指定の次の各プロパティとして
|
---|---|
適用対象 | グリッドコンテナー |
継承 | なし |
パーセント値 | 一括指定の次の各プロパティとして
|
計算値 | 一括指定の次の各プロパティとして
|
アニメーションの種類 | 離散値 |
ブラウザーの対応
BCD tables only load in the browser
関連情報
- 関連する CSS プロパティ:
grid-template
,grid-template-rows
,grid-template-columns
,grid-template-areas
,grid-auto-columns
,grid-auto-rows
,grid-auto-flow
- グリッドレイアウトガイド: CSS グリッドでの行ベースの配置
- グリッドレイアウトガイド: グリッドテンプレート領域 - グリッド定義の一括指定