flex
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 CSS ìì±ì íëì íë ì¤ ìì´í
ì´ ìì ì 컨í
ì´ëê° ì°¨ì§íë ê³µê°ì ë§ì¶ê¸° ìí´ í¬ê¸°ë¥¼ í¤ì°ê±°ë ì¤ì´ë ë°©ë²ì ì¤ì íë ìì±ì
ëë¤. flexë flex-grow, flex-shrink, flex-basisì ë¨ì¶ ìì±ì
ëë¤.
ìëí´ ë³´ê¸°
flex: 1;
flex: 2;
flex: 1 30px;
flex: 1 1 100px;
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">Change me</div>
<div>flex: 1</div>
<div>flex: 1</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: 0;
}
#example-element {
background-color: rgba(255, 0, 200, 0.2);
border: 3px solid rebeccapurple;
}
ëë¶ë¶ì ê²½ì°, flexì ê°ìë auto, initial, noneì´ë ë¨ì ìë ìì ì를 ì¬ì©í´ì¼ í©ëë¤. ê° ê°ì ì ì© í¨ê³¼ë¥¼ ë³´ë ¤ë©´ ìë íë ì¤ ì»¨í
ì´ëì í¬ê¸°ë¥¼ ì¡°ì í´ë³´ì¸ì.
기본ì ì¼ë¡ íë ì¤ ìì´í
ì ì½í
ì¸ ì ìµì ëë¹ ë¯¸ë§ì¼ë¡ ì¤ì´ë¤ì§ ììµëë¤. min-widthë min-height ê°ì ì§ì í´ ë°ê¿ ì ììµëë¤.
구문
/* Keyword values */
flex: auto;
flex: initial;
flex: none;
/* One value, unitless number: flex-grow */
flex: 2;
/* One value, length or percentage: flex-basis */
flex: 10em;
flex: 30%;
/* Two values: flex-grow | flex-basis */
flex: 1 30px;
/* Two values: flex-grow | flex-shrink */
flex: 2 2;
/* Three values: flex-grow | flex-shrink | flex-basis */
flex: 2 2 10%;
/* Global values */
flex: inherit;
flex: initial;
flex: unset;
flex ìì±ì í ê°ìì ì¸ ê°ì ê°ì ì¬ì©í´ ì§ì í ì ììµëë¤.
-
ê°ì´ í ê°ì¼ ë, ê·¸ ê°ì ë¤ì ì¤ íëì¬ì¼ í©ëë¤.
<number>를 ì§ì íë©´<flex-grow>ì ëë¤.<length>ëë<percentage>를 ì§ì íë©´<flex-basis>ì ëë¤.none,auto,initialì¤ íë를 ì§ì í ì ììµëë¤.
-
ê°ì´ ë ê°ì¼ë, 첫 ë²ì§¸ ê°ì
<number>ì¬ì¼ íë©°<flex-grow>ê° ë©ëë¤. ë ë²ì§¸ ê°ì ë¤ì ì¤ íëì¬ì¼ í©ëë¤.<number>를 ì§ì íë©´<flex-shrink>ì ëë¤.<length>,<percentage>, ëëauto를 ì§ì íë©´<flex-basis>ì ëë¤.
-
ê°ì´ ì¸ ê°ì¼ ëë ë¤ì ìì를 ë°ë¼ì¼ í©ëë¤.
<flex-grow>ì ì¬ì©í<number><flex-shrink>ì ì¬ì©í<number><flex-basis>ì ì¬ì©í<length>,<percentage>, ëëauto
ê°
initial-
ìì´í í¬ê¸°ê° ê°ê°ì
widthìheightìì±ì ë°ë¼ ì í´ì§ëë¤. íë ì¤ ì»¨í ì´ëì í¬ê¸°ë¥¼ ëì§ ì기 ìí´ ìµì í¬ê¸°ë¡ ì¤ì´ë¤ ìë ìì§ë§, ë¨ì ê³µê°ì ì±ì°ë ¤ ëì´ëì§ë ììµëë¤.flex: 0 1 autoì ëì¼í©ëë¤. auto-
ìì´í í¬ê¸°ê° ê°ê°ì
widthìheightìì±ì ë°ë¼ ì í´ì§ëë¤. íë ì¤ ì»¨í ì´ëì í¬ê¸°ë¥¼ ëì§ ì기 ìí´ ìµì í¬ê¸°ë¡ ì¤ì´ë¤ ì ìì¼ë©°, ë¨ì ê³µê°ì ì±ì°ê¸° ìí´ ëì´ë ìë ììµëë¤.flex: 1 1 autoì ëì¼í©ëë¤. none-
ìì´í í¬ê¸°ê° ê°ê°ì
widthìheightìì±ì ë°ë¼ ì í´ì§ë©°, 컨í ì´ëì í¬ê¸°ì ê´ê³ ìì´ ë³íì§ ììµëë¤.flex: 0 0 autoì ëì¼í©ëë¤. <'flex-grow'>-
íë ì¤ ìì´í ì
flex-grow를 ì§ì í©ëë¤. ìì ê°ì ì í¨íì§ ììµëë¤. ìëµ ì 기본ê°ì0ì ëë¤. <'flex-shrink'>-
íë ì¤ ìì´í ì
flex-shrink를 ì§ì í©ëë¤. ìì ê°ì ì í¨íì§ ììµëë¤. ìëµ ì 기본ê°ì1ì ëë¤. <'flex-basis'>-
íë ì¤ ìì´í ì
flex-basis를 ì§ì í©ëë¤.0ì ì§ì íë ¤ë©´<flex-grow>ëë<flex-shrink>ë¡ ì½íì§ ìëë¡ ë¨ì를 ë¶ì¬ì¼ í©ëë¤. ìëµ ì 기본ê°ìautoì ëë¤.
ì°¸ê³ :
í ê° ëë ë ê°ì ë¨ì ìë ì«ì ê°ì ì¬ì©í ë, <flex-basis>ì ê°ì autoê° ìëë¼ 0ì´ ë©ëë¤. ë ìì¸í ì ë³´ë íë ìë¸ ë°ì¤ ë ì´ìì 모ë ì´ììì íì¸í ì ììµëë¤.
íì 구문
flex =
none |
[ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
<flex-grow> =
<number [0,â]>
<flex-shrink> =
<number [0,â]>
<flex-basis> =
content |
<'width'>
<width> =
auto |
<length-percentage [0,â]> |
min-content |
max-content |
fit-content( <length-percentage [0,â]> ) |
<calc-size()> |
<anchor-size()> |
stretch |
fit-content |
contain
<length-percentage> =
<length> |
<percentage>
<calc-size()> =
calc-size( <calc-size-basis> , <calc-sum> )
<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )
<calc-size-basis> =
<size-keyword> |
<calc-size()> |
any |
<calc-sum>
<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*
<anchor-name> =
<dashed-ident>
<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline
<calc-product> =
<calc-value> [ [ '*' | / ] <calc-value> ]*
<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )
<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN
ìì
#flex-container {
display: flex;
flex-direction: row;
}
#flex-container > .flex-item {
flex: auto;
}
#flex-container > .raw-item {
width: 5rem;
}
<div id="flex-container">
<div class="flex-item" id="flex">Flex box (click to toggle raw box)</div>
<div class="raw-item" id="raw">Raw box</div>
</div>
ê²°ê³¼
ëª ì¸
| Specification |
|---|
| CSS Flexible Box Layout Module Level 1 > # flex-property > |
| ì´ê¸°ê° | as each of the properties of the shorthand:
|
|---|---|
| ì ì©ëì | flex items, including in-flow pseudo-elements |
| ìì | no |
| ê³ì° ê° | as each of the properties of the shorthand:
|
| Animation type | as each of the properties of the shorthand:
|
ë¸ë¼ì°ì í¸íì±
ê°ì´ 보기
- CSS íë ì¤ë°ì¤ ìë´ì: Basic Concepts of Flexbox
- CSS íë ì¤ë°ì¤ ìë´ì: Controlling Ratios of flex items along the main axis