flex-shrink
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 9ì.
flex-shrink CSS propertyë flex-item ììì flex-shrink ê°ì ì¤ì íë ìì±ì
ëë¤. ë§ì½ flex-item ììì í¬ê¸°ê° flex-container ììì í¬ê¸°ë³´ë¤ í´ ë flex-shrink ìì±ì ì¬ì©íëë°, ì¤ì ë ì«ìê°ì ë°ë¼ flex-container ìì ë´ë¶ìì flex-item ììì í¬ê¸°ê° ì¶ìë©ëë¤.
ìëí´ ë³´ê¸°
flex-shrink: 0;
flex-shrink: 1;
flex-shrink: 2;
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">I shrink</div>
<div>Item Two</div>
<div>Item Three</div>
</section>
.default-example {
border: 1px solid #c5c5c5;
width: auto;
max-height: 300px;
display: flex;
}
.default-example > div {
background-color: rgba(0, 0, 255, 0.2);
border: 3px solid blue;
margin: 10px;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 300px;
}
Syntax
css
/* <number> values */
flex-shrink: 2;
flex-shrink: 0.6;
/* Global values */
flex-shrink: inherit;
flex-shrink: initial;
flex-shrink: unset;
The flex-shrink property is specified as a single <number>.
Values
Formal syntax
flex-shrink =
<number [0,â]>
Example
>HTML
html
<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>
CSS
css
#content {
display: flex;
width: 500px;
}
#content div {
flex-basis: 120px;
border: 3px solid rgba(0, 0, 0, 0.2);
}
.box {
flex-shrink: 1;
}
.box1 {
flex-shrink: 2;
}
Result
ëª ì¸ì
| Specification |
|---|
| CSS Flexible Box Layout Module Level 1 > # flex-shrink-property > |
| ì´ê¸°ê° | 1 |
|---|---|
| ì ì©ëì | flex items, including in-flow pseudo-elements |
| ìì | no |
| ê³ì° ê° | as specified |
| Animation type | a number |
ë¸ë¼ì°ì í¸íì±
See also
- CSS Flexbox Guide: Basic Concepts of Flexbox
- CSS Flexbox Guide: Controlling Ratios of flex items along the main axis