flex-shrink
CSS
property sets the flex shrink factor of a flex item. If the size of all flex items is larger than the flex container, items shrink to fit according to
flex-shrink
.
In use,
flex-shrink
is used alongside the other flex properties
flex-grow
and
flex-basis
, and normally defined using the
flex
shorthand.
/* <number> values */ flex-shrink: 2; flex-shrink: 0.6; /* Global values */ flex-shrink: inherit; flex-shrink: initial; flex-shrink: unset;
flex-shrink
property is specified as a single
<number>
.
<number>
<number>
. Negative values are invalid. Defaults to 1.
| 初始值 |
1
|
|---|---|
| 适用于 | flex items, including in-flow pseudo-elements |
| 继承 | no |
| 计算值 | 如指定 |
| 动画类型 | a number |
<number>
<p>The width of content is 500px; the flex-basis of the flex items is 120px.</p> <p>A, B, C have flex-shrink:1 set. D and E have flex-shrink:2 set</p> <p>The width of D and E is less than the others.</p> <div id="content"> <div class="box" style="background-color:red;">A</div> <div class="box" style="background-color:lightblue;">B</div> <div class="box" style="background-color:yellow;">C</div> <div class="box1" style="background-color:brown;">D</div> <div class="box1" style="background-color:lightgreen;">E</div> </div>
#content {
display: flex;
width: 500px;
}
#content div {
flex-basis: 120px;
border: 3px solid rgba(0,0,0,.2);
}
.box {
flex-shrink: 1;
}
.box1 {
flex-shrink: 2;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Flexible Box Layout Module
The definition of 'flex-shrink' in that specification. |
候选推荐 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
flex-shrink
|
Chrome 完整支持 29 | Edge 完整支持 12 |
Firefox
完整支持
20
注意事项
|
IE
完整支持
10
注意事项
|
Opera 完整支持 12.1 | Safari 完整支持 9 | WebView Android 完整支持 4.4 | Chrome Android 完整支持 29 |
Firefox Android
完整支持
20
注意事项
|
Opera Android 完整支持 12.1 | Safari iOS 完整支持 9 | Samsung Internet Android 完整支持 2.0 |
完整支持
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
flex
flex-basis
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
order