minmax()
CSS
function
defines a size range greater than or equal to
min
and less than or equal to
max
. It is used with
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)
A function taking two parameters, min and max .
Each parameter can be a
<length>
,
<percentage>
,
<flex>
value, or one of the keyword values
max-content
,
min-content
,或
auto
.
若
max
<
min
, then
max
is ignored and
minmax(min,max)
is treated as
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>
<percentage>
must be treated as
auto
。
用户代理
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>
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
max-content
. As a minimum it represents the largest minimum size (as specified by
min-width
/
min-height
) of the grid items occupying the grid track.
minmax( [ <length> | <percentage> | min-content | max-content | auto ] , [ <length> | <percentage> | <flex> | min-content | max-content | auto ] )
minmax()
function can be used within:
#container {
display: grid;
grid-template-columns: minmax(min-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;
}
<div id="container">
<div>
Item as wide as the content, 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 栅格布局
The definition of 'minmax()' in that specification. |
候选推荐 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
minmax()
|
Chrome
完整支持
57
|
Edge 完整支持 16 |
Firefox
完整支持
52
|
IE 不支持 No |
Opera
完整支持
44
|
Safari 完整支持 10.1 | WebView Android 完整支持 57 |
Chrome Android
完整支持
57
|
Firefox Android
完整支持
52
|
Opera Android
完整支持
43
|
Safari iOS 完整支持 10.3 | Samsung Internet Android 完整支持 6.0 |
完整支持
不支持
用户必须明确启用此特征。
Video tutorial: Introducing minmax()