CSSグリッドプロパティ
例
最初の行の高さが150ピクセルの3列のグリッドレイアウトを作成します。
.grid-container {
display: grid;
grid: 150px
/ auto auto auto;
}
定義と使用法
プロパティは、次のgrid
略記プロパティです。
- grid-template-rows
- grid-template-columns
- grid-template-areas
- grid-auto-rows
- grid-auto-columns
- グリッド-自動フロー
デフォルト値: | なしなしなし自動自動行 |
---|---|
遺伝性の: | いいえ |
アニメート可能: | はい、個々のプロパティを参照してください。アニメート可能について読む |
バージョン: | CSSグリッドレイアウトモジュールレベル1 |
JavaScript構文: | object .style.grid = "250px / auto auto auto" |
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
Property | |||||
---|---|---|---|---|---|
grid | 57 | 16 | 52 | 10 | 44 |
CSS構文
grid: none|grid-template-rows /
grid-template-columns|grid-template-areas|grid-template-rows
/ [grid-auto-flow] grid-auto-columns|[grid-auto-flow] grid-auto-rows / grid-template-columns|initial|inherit;
プロパティ値
Value | Description | Play it |
---|---|---|
none | Default value. No specific sizing of the columns or rows | |
grid-template-rows / grid-template-columns | Specifies the size(s) of the columns and rows | |
grid-template-areas | Specifies the grid layout using named items | |
grid-template-rows / grid-auto-columns | Specifies the size (height) of the rows, and the auto size of the columns | |
grid-auto-rows / grid-template-columns | Specifies the auto size of the rows, and sets the grid-template-columns property | |
grid-template-rows / grid-auto-flow grid-auto-columns | Specifies the size (height) of the rows, and how to place auto-placed items, and the auto size of the columns | |
grid-auto-flow grid-auto-rows / grid-template-columns | Specifies how to place auto-placed items, and the auto size of the rows, and sets the grid-template-columns property | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
その他の例
例
2行を指定します。ここで、「item1」は最初の2行の最初の2列にまたがっています(5列のグリッドレイアウト)。
.item1 {
grid-area: myArea;
}
.grid-container {
display: grid;
grid:
'myArea myArea . . .'
'myArea myArea . . .';
}
例
すべてのアイテムに名前を付け、すぐに使用できるWebページテンプレートを作成します。
.item1 { grid-area: header; }
.item2 { grid-area:
menu; }
.item3 { grid-area:
main; }
.item4 { grid-area:
right; }
.item5 { grid-area:
footer; }
.grid-container {
display: grid;
grid:
'header header header header header'
'menu main main main right right'
'menu footer footer
footer footer';
}
関連ページ
CSSチュートリアル:CSSグリッドコンテナ
CSSリファレンス:grid-template-areasプロパティ
CSSリファレンス:grid-template-rowsプロパティ
CSSリファレンス:grid-template-columnsプロパティ
CSSリファレンス:grid-auto-rowsプロパティ
CSSリファレンス:grid-auto-columnsプロパティ
CSSリファレンス:grid-auto-flowプロパティ
CSSリファレンス:grid-row-gapプロパティ
CSSリファレンス:grid-column-gapプロパティ