Вы читаете английскую версию этой статьи, так как пока нет перевода на данный язык. Помогите нам перевести эту статью!
minmax
()
это CSS функция, определяющая диапазон размеров, который больше или равен min и меньше или равен max. Используется в CSS Grids.
/* <inflexible-breadth>, <track-breadth> values */ minmax(200px, 1fr) minmax(400px, 50%) minmax(30%, 300px) minmax(100px, max-content) minmax(min-content, 400px) minmax(max-content, auto) minmax(auto, 300px) minmax(min-content, auto) /* <fixed-breadth>, <track-breadth> values */ minmax(200px, 1fr) minmax(30%, 300px) minmax(400px, 50%) minmax(50%, min-content) minmax(300px, max-content) minmax(200px, auto) /* <inflexible-breadth>, <fixed-breadth> values */ minmax(400px, 50%) minmax(30%, 300px) minmax(min-content, 200px) minmax(max-content, 200px) minmax(auto, 300px)
Синтаксис
Функция принимает два параметра, min и max.
Каждый параметр может быть значением <length>
, либо <percentage>
, либо <flex>
, или одним из ключевых слов max-content
, min-content
, или auto
.
Если max < min, то max игнорируется и minmax(min,max)
обрабатывается как min. As a maximum, a <flex>
value sets the flex factor of a grid track; it is invalid as a minimum.
Значения
<length>
- A non-negative length.
<percentage>
- A non-negative percentage relative to the inline size of the grid container in column grid tracks, and the block size of the grid container in row grid tracks. If the size of the grid container depends on the size of its tracks, then the
<percentage>
must be treated asauto
. The user agent may adjust the intrinsic size contributions of the track to the size of the grid container and increase the final size of the track by the minimum amount that would result in honoring the percentage. <flex>
- A non-negative dimension with the unit
fr
specifying the track’s flex factor. Each<flex>
-sized track takes a share of the remaining space in proportion to its flex factor. max-content
- Represents the largest max-content contribution of the grid items occupying the grid track.
min-content
- Represents the largest min-content contribution of the grid items occupying the grid track.
auto
- As a maximum, identical to
max-content
. As a minimum it represents the largest minimum size (as specified bymin-width
/min-height
) of the grid items occupying the grid track.
Формальный синтаксис
minmax( [ <length> | <percentage> | <flex> | min-content | max-content | auto ] , [ <length> | <percentage> | <flex> | min-content | max-content | auto ] )
Пример
CSS
#container { display: grid; grid-template-columns: minmax(max-content, 300px) minmax(200px, 1fr) 150px; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; }
HTML
<div id="container"> <div> Item as wide as the content,<br/> but at most 300 pixels. </div> <div> Item with flexible width but a minimum of 200 pixels. </div> <div> Inflexible item of 150 pixels width. </div> </div>
Результат
Спецификации
Спецификация | Статус | Комментарий |
---|---|---|
CSS Grid Layout Определение 'minmax()' в этой спецификации. |
Кандидат в рекомендации | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Компьютеры | Мобильные | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
minmax() | Chrome
Полная поддержка
57
| Edge Полная поддержка 16 | Firefox
Полная поддержка
52
| IE Нет поддержки Нет | Opera
Полная поддержка
44
| Safari Полная поддержка 10.1 | WebView Android Полная поддержка 57 | Chrome Android
Полная поддержка
57
| Firefox Android
Полная поддержка
52
| Opera Android
Полная поддержка
43
| Safari iOS Полная поддержка 10.3 | Samsung Internet Android ? |
Легенда
- Полная поддержка
- Полная поддержка
- Нет поддержки
- Нет поддержки
- Совместимость неизвестна
- Совместимость неизвестна
- Пользователь должен сам включить эту возможность.
- Пользователь должен сам включить эту возможность.
Смотрите также
- Grid Layout Guide: Basic concepts of grid layout - track sizing with minmax()
- Video tutorial: Introducing minmax()