Свойство CSS grid-template
Пример
Создайте макет сетки из трех столбцов, где первая строка имеет высоту 150 пикселей:
.grid-container {
display: grid;
grid-template: 150px
/ auto auto auto;
}
Определение и использование
Свойство grid-template
является сокращенным свойством для следующих свойств:
Значение по умолчанию: | никто никто никто |
---|---|
Унаследовано: | нет |
Анимация: | да. Читать об анимации |
Версия: | Модуль CSS Grid Layout Уровень 1 |
Синтаксис JavaScript: | объект .style.gridTemplate="250px / авто авто" |
Поддержка браузера
Цифры в таблице указывают на первую версию браузера, которая полностью поддерживает это свойство.
Property | |||||
---|---|---|---|---|---|
grid-template | 57 | 16 | 52 | 10 | 44 |
Синтаксис CSS
grid-template: none|grid-template-rows /
grid-template-columns|grid-template-areas|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 | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Дополнительные примеры
Пример
Укажите две строки, где «item1» охватывает первые два столбца в первых двух строках (в сетке из пяти столбцов):
.item1 {
grid-area: myArea;
}
.grid-container {
display: grid;
grid-template:
'myArea myArea . . .'
'myArea myArea . . .';
}
Пример
Назовите все элементы и создайте готовый к использованию шаблон веб-страницы:
.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-template:
'header header header header header header'
'menu main main main right right'
'menu footer footer
footer footer footer';
}
Связанные страницы
Учебное пособие по CSS: элемент сетки CSS
Справочник по CSS: свойство grid-area
Справочник по CSS: свойство grid-template-rows
Справочник по CSS: свойство grid-template-columns
Справочник по CSS: свойство grid-template-areas