Свойство CSS grid-template-columns
Пример
Создайте сетку-контейнер из 4 столбцов:
.grid-container {
display: grid;
grid-template-columns:
auto auto auto auto;
}
Определение и использование
Свойство grid-template-columns
указывает количество (и ширину) столбцов в макете сетки.
Значения представляют собой список, разделенный пробелами, где каждое значение указывает размер соответствующего столбца.
Значение по умолчанию: | никто |
---|---|
Унаследовано: | нет |
Анимация: | да. Читать об анимации |
Версия: | Модуль CSS Grid Layout Уровень 1 |
Синтаксис JavaScript: | объект .style.gridTemplateColumns="50px 50px 50px" |
Поддержка браузера
Цифры в таблице указывают на первую версию браузера, которая полностью поддерживает это свойство.
Property | |||||
---|---|---|---|---|---|
grid-template-columns | 57 | 16 | 52 | 10 | 44 |
Синтаксис CSS
grid-template-columns: none|auto|max-content|min-content|length|initial|inherit;
Значения свойств
Value | Description | Play it |
---|---|---|
none | Default value. Columns are created if needed | |
auto | The size of the columns is determined by the size of the container and on the size of the content of the items in the column | |
max-content | Sets the size of each column to depend on the largest item in the column | |
min-content | Sets the size of each column to depend on the smallest item in the column | |
length | Sets the size of the columns, by using a legal length value. Read about length units | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Дополнительные примеры
Пример
Создайте контейнер сетки из 4 столбцов и укажите размер для каждого столбца:
.grid-container {
display: grid;
grid-template-columns:
30px 200px auto 100px;
}
Связанные страницы
Учебник по CSS: CSS Grid Layout
Справочник по CSS: свойство grid-template-rows
Справочник по CSS: свойство grid-template