CSS ์์ฑ 16. flex
โ๏ธ ํด๋น ๊ธ์ ํจ์คํธ์บ ํผ์ค - ํ๋ก ํธ์๋ ๊ฐ๋ฐ ๊ฐ์์์ HTML & CSS, SASS(SCSS) Part์ ๋ฐ์์ ๊ฐ์ฌ๋์ ๊ฐ์์๋ฃ๋ฅผ ์ ๋ฆฌํ ๊ฒ์ ๋๋ค.
flex ๋ ์น ํ์ด์ง์์ ์ํ ๊ตฌ์กฐ ๋ ์ด์์์ ์ฝ๊ณ ๋ช
ํํ๊ฒ ๊ตฌ์ฑํ ์ ์๋ ๋ฐฉ๋ฒ์ด๋ค.
flex ์ด์ ์ ๋ฐฉ๋ฒ๋ค๊ณผ์ ๋น๊ต#
inline-block#
<div class="container"><div class="item">1</div><div class="item">2</div><div class="item">3</div></div>.container {border: 2px solid red;font-size: 0;}.container .item {width: 100px;height: 100px;border: 2px solid;border-radius: 10px;display: inline-block;font-size: 16px;}โ๏ธ inline-block ์ block ์์๋ฅผ inline ์์(ํ ์คํธ)์ฒ๋ผ ๋ค๋ฃจ๊ฒ ๋๊ณ , ์ด๋ ์์์ฌ์ด์ ๊ณต๋ฐฑ์ ์ ๊ฑฐํ๊ธฐ ์ํ font-size ์์ ์ ๋ถ๋ฌ์ค๋ ๋ฑ ์ข์ง ์์ ๋ฐฉ๋ฒ์ด๋ค.
float ์์ฑ#
<div class="container clearfix"><div class="item">1</div><div class="item">2</div><div class="item">3</div></div>.clearfix::after {content: "";display: block;clear: both;}.container {border: 2px solid red;}.container .item {width: 100px;height: 100px;border: 2px solid;border-radius: 10px;float: left;}โ๏ธ float ์ด๋ผ๋ ์์ฑ์ด ์์๋ฅผ ์ํํํ๋๋ฐ ์ ๋ฌธ์ ์ผ๋ก ์ฌ์ฉ๋๋ ์์ฑ์ด ์๋๋ค.
flex#
<div class="container"><div class="item">1</div><div class="item">2</div><div class="item">3</div></div>.container {border: 2px solid red;display: flex;}.container .item {width: 100px;height: 100px;border: 2px solid;border-radius: 10px;float: left;}โ๏ธ flex ๊ฐ ์ํ ๊ตฌ์กฐ๋ฅผ ๋ง๋๋ ๊ฐ์ฅ ๊ฐํธํ๊ณ ๋ช ํํ ๋ฐฉ๋ฒ์ด๋ค.
CSS3 Flexible Box#
flex ๋ ์์์ ํฌ๊ธฐ๊ฐ ๋ถ๋ถ๋ช
ํ๊ฑฐ๋ ๋์ ์ธ ๊ฒฝ์ฐ์๋, ๊ฐ ์์๋ฅผ ์ ๋ ฌํ ์ ์๋ํจ์จ์ ์ธ ๋ฐฉ๋ฒ์ด๋ค.
flex ๋ 2๊ฐ์ ๊ฐ๋
์ผ๋ก ๋๋๋๋ฐ 1. container, 2. items ์ด๋ค.
container ๋ items ๋ฅผ ๊ฐ์ธ๋ ๋ถ๋ชจ ์์์ด๊ณ , ๊ฐ item ์ ์ ๋ ฌํ๊ธฐ ์ํด container ๊ฐ ํ์์ ์ด๋ค.
container ์ items ์ ์ ์ฉํ๋ ์์ฑ์ด ๊ตฌ๋ถ๋์ด ์๋๋ฐ, container ์๋ display , flex-flow , justify-content ๋ฑ์ ์์ฑ์ ์ฌ์ฉํ ์ ์๊ณ , items ์๋ order , flex , align-self ๋ฑ์ ์์ฑ์ ์ฌ์ฉํ ์ ์๋ค.

container-items
flex container#
์์ฑ#
| ์์ฑ | ์๋ฏธ |
|---|---|
| display | flex container ๋ฅผ ์ ์ |
| flex-flow | flex-direction ์ flex-wrap ์ ๋จ์ถ ์์ฑ |
| flex-direction | flex items ์ ์ฃผ ์ถ(main-axis)์ ์ค์ |
| flex-wrap | flex items ์ ์ฌ๋ฌ ์ค ๋ฌถ์(์ค ๋ฐ๊ฟ) ์ค์ |
| justify-content | ์ฃผ ์ถ(main-axis)์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ |
| align-content | ๊ต์ฐจ ์ถ(cross-axis)์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ (2์ค ์ด์) |
| align-items | ๊ต์ฐจ ์ถ(cross-axis)์์ items ์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ (1์ค) |
display#
display ์์ฑ์ผ๋ก flex container ๋ฅผ ์ ์ํ๋ค.
๋ณดํต display: block; , display: inline , display: inline-block , display: none; ์ผ๋ก ์ฌ์ฉํ์๋๋ฐ, ( Property-06-display ์ฐธ์กฐ) display: flex; ๋๋ display: inline-flex; ๋ ์ฌ์ฉํ ์ ์๋ค.
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| flex | Block ํน์ฑ์ flex container ๋ฅผ ์ ์ | |
| inline-flex | Inline ํน์ฑ์ flex container ๋ฅผ ์ ์ |
flex ์ inline-flex ์ ์ฐจ์ด๋ ๋ค์๊ณผ ๊ฐ๋ค.

flex-display
display: flex; ๋ก ์ง์ ๋ flex container ๋ block ์์์ ๊ฐ์ด ์์ง์ผ๋ก ์์ด๋ฉฐ,
display: inline-flex; ๋ก ์ง์ ๋ flex container ๋ inline ์์์ ๊ฐ์ด ์ํ์ผ๋ก ์์ธ๋ค.
โ๏ธ flex ์ inline-flex ์ ๋ด๋ถ์ items ๊ฐ ์์ด๋ ๋ฐฉ์์ ๋์ด ์์ ํ ๊ฐ๋ค.
flex-flow#
flex items ์ ์ฃผ ์ถ(main-axis)์ items ์ ์ฌ๋ฌ ์ค ๋ฌถ์(์ค ๋ฐ๊ฟ) ์ค์ - ๋จ์ถ์์ฑ
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| flex-direction | items ์ ์ฃผ ์ถ(main-axis)์ ์ค์ | row |
| flex-wrap | items์ ์ฌ๋ฌ ์ค ๋ฌถ์(์ค ๋ฐ๊ฟ) ์ค์ | nowrap |
์ฌ์ฉ๋ฒ#
flex-flow: ์ฃผ์ถ ์ฌ๋ฌ์ค๋ฌถ์;.flex-container {flex-flow: row-reverse wrap;}flex-direction#
Items ์ ์ฃผ ์ถ(main-axis) ์ค์
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| row | Items ๋ฅผ ์ํ์ถ(์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก)์ผ๋ก ํ์ | row |
| row-reverse | Items ๋ฅผ row ์ ๋ฐ๋ ์ถ์ผ๋ก ํ์ | |
| column | Items ๋ฅผ ์์ง์ถ(์์์ ์๋๋ก)์ผ๋ก ํ์ | |
| column-reverse | Items ๋ฅผ column ์ ๋ฐ๋ ์ถ์ผ๋ก ํ์ |

flex-direction
์ฃผ ์ถ(main-axis)๊ณผ ๊ต์ฐจ ์ถ(cross-axis)#
row ๋ items ๋ฅผ ์ํ์ถ์ผ๋ก ํ์ํ๋ฏ๋ก ์ฃผ ์ถ์ด ์ํ์ด๋ฉฐ ๊ต์ฐจ ์ถ์ ์์ง์ด ๋๋ค .
๋ฐ๋๋ก column ์ items ๋ฅผ ์์ง์ถ์ผ๋ก ํ์ํ๋ฏ๋ก ์ฃผ ์ถ์ ์์ง์ด๋ฉฐ ๊ต์ฐจ ์ถ์์ํ์ด ๋๋ค.
โ๏ธ ๋ฐฉํฅ์ ๋ฐ๋ผ ์ฃผ ์ถ๊ณผ ๊ต์ฐจ ์ถ์ด ๋ฌ๋ผ์ง๋ค.

flex-direction-main-axis
์์์ (flex-start)๊ณผ ๋์ (flex-end)#
์ฃผ ์ถ(main-axis)์ด๋ ๊ต์ฐจ ์ถ(cross-axis)์ ์์ํ๋ ์ง์ ๊ณผ ๋๋๋ ์ง์ ์ ์ง์นญ.
์ด ์ญ์ ๋ฐฉํฅ์ ๋ฐ๋ผ ์์์ (flex-start)๊ณผ ๋์ (flex-end)์ด ๋ฌ๋ผ์ง๋ค.

flex-direction-main-start

flex-direction-cross-start
โ๏ธ ๊ต์ฐจ์ถ์ ์์์ (flex-start)๊ณผ ๋์ (flex-end)์ ๋ฌ๋ผ์ง์ง ์๋๋ค.
flex-wrap#
items ์ ์ฌ๋ฌ ์ค ๋ฌถ์(์ค ๋ฐ๊ฟ)์ ์ค์ ํ๋ค.
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| nowrap | ๋ชจ๋ items ๋ฅผ ์ฌ๋ฌ ์ค๋ก ๋ฌถ์ง ์์(ํ ์ค์ ํ์) | nowrap |
| wrap | items ๋ฅผ ์ฌ๋ฌ ์ค๋ก ๋ฌถ์ | |
| wrap-reverse | items ๋ฅผ wrap ์ ์ญ ๋ฐฉํฅ์ผ๋ก ์ฌ๋ฌ ์ค๋ก ๋ฌถ์ |
โ๏ธ ๊ธฐ๋ณธ๊ฐ์ผ๋ก nowrap ์ด ์ค์ ๋์ด ์๊ธฐ ๋๋ฌธ์ items ๋ ํ ์ค์์๋ง ํ์๋๊ณ ์ค๋ฐ๊ฟ ๋์ง ์์ผ๋ฉฐ ์ง์ ๋ ํฌ๊ธฐ(์ฃผ ์ถ์ ๋ฐ๋ผ width ๋ height )๋ฅผ ๋ฌด์ํ๊ณ ํ ์ค์์์๋ง ๊ฐ๋ณํ๋ค.

flex-wrap
์์ #
<div class="container"><div class="item">A</div><div class="item">B</div><div class="item">C</div><div class="item">D</div><div class="item">E</div></div>.container {border: 4px solid;display: flex;flex-wrap: wrap;}.container .item {width: 150px;height: 100px;background: tomato;border: 4px dashed red;}justify-content#
์ฃผ ์ถ(main-axis)์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ ํ๋ค.
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| flex-start | items ๋ฅผ ์์์ (flex-start)์ผ๋ก ์ ๋ ฌ | flex-start |
| flex-end | items ๋ฅผ ๋์ (flex-end)์ผ๋ก ์ ๋ ฌ | |
| center | items ๋ฅผ ๊ฐ์ด๋ฐ ์ ๋ ฌ | |
| space-between | ์์ item ์ ์์์ ์, ๋ง์ง๋ง item ์ ๋์ ์ ์ ๋ ฌ๋๊ณ , ๋๋จธ์ง items ๋ ์ฌ์ด์ ๊ณ ๋ฅด๊ฒ ์ ๋ ฌ๋จ | |
| space-around | items ๋ฅผ ๊ท ๋ฑํ ์ฌ๋ฐฑ์ ํฌํจํ์ฌ ์ ๋ ฌ |

flex-justify-content
์์ #
<div class="container"><div class="item">A</div><div class="item">B</div><div class="item">C</div><div class="item">D</div></div>.container {border: 4px solid;display: flex;justify-content: center;}.container .item {width: 100px;height: 100px;background: tomato;border: 4px dashed red;border-radius: 10px;}align-content#
๊ต์ฐจ ์ถ(cross-axis)์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์
flex-wrap ์์ฑ์ ํตํด items ๊ฐ ์ฌ๋ฌ ์ค(2์ค ์ด์)์ด๊ณ ์ฌ๋ฐฑ์ด ์์ ๊ฒฝ์ฐ๋ง ์ฌ์ฉํ ์ ์๋ค.
โ๏ธ items ๊ฐ ํ ์ค์ผ ๊ฒฝ์ฐ align-items ๋ฅผ ์ฌ์ฉ
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| stretch | container ์ ๊ต์ฐจ ์ถ์ ์ฑ์ฐ๊ธฐ ์ํด items ๋ฅผ ๋๋ฆผ | stretch |
| flex-start | items ๋ฅผ ์์์ (flex-start)์ผ๋ก ์ ๋ ฌ | |
| flex-end | items ๋ฅผ ๋์ (flex-end)์ผ๋ก ์ ๋ ฌ | |
| center | items ๋ฅผ ๊ฐ์ด๋ฐ ์ ๋ ฌ | |
| space-between | ์์ item ์ ์์์ ์, ๋ง์ง๋ง item ์ ๋์ ์ ์ ๋ ฌ๋๊ณ ๋๋จธ์ง items ๋ ์ฌ์ด์ ๊ณ ๋ฅด๊ฒ ์ ๋ ฌ๋จ | |
| space-around | items ๋ฅผ ๊ท ๋ฑํ ์ฌ๋ฐฑ์ ํฌํจํ์ฌ ์ ๋ ฌ |
โ๏ธ stretch ๋ ๊ต์ฐจ ์ถ์ ํด๋นํ๋ ๋๋น(์์ฑ width ํน์ height )๊ฐ ๊ฐ์ด auto (๊ธฐ๋ณธ๊ฐ)์ผ ๊ฒฝ์ฐ ๊ต์ฐจ ์ถ์ ์ฑ์ฐ๊ธฐ ์ํด ์๋์ผ๋ก ๋์ด๋๋ค.

flex-align-content
์์ #
<div class="container"><div class="item">A</div><div class="item">B</div><div class="item">C</div><div class="item">D</div><div class="item">E</div><div class="item">F</div></div>.container {height: 400px;border: 4px solid;display: flex;flex-wrap: wrap;align-content: center;}.container .item {width: 120px;height: 100px;background: tomato;border: 4px dashed red;border-radius: 10px;}align-items#
๊ต์ฐจ ์ถ(cross-axis)์์ items ์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ ํ๋ค.
items ๊ฐ ํ ์ค์ผ ๊ฒฝ์ฐ ๋ง์ด ์ฌ์ฉํ๋ค.
โ๏ธ items ๊ฐ flex-wrap ์ ํตํด ์ฌ๋ฌ ์ค(2์ค ์ด์)์ผ ๊ฒฝ์ฐ์๋ align-content ์์ฑ์ด ์ฐ์ ํ๋ค.๋ฐ๋ผ์ align-items ๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด align-content ์์ฑ์ ๊ธฐ๋ณธ๊ฐ( stretch )์ผ๋ก ์ค์ ํด์ผ ํ๋ค.
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| stretch | container ์ ๊ต์ฐจ ์ถ์ ์ฑ์ฐ๊ธฐ ์ํด items ๋ฅผ ๋๋ฆผ | stretch |
| flex-start | items ๋ฅผ ์์์ (flex-start)์ผ๋ก ์ ๋ ฌ | |
| flex-end | items ๋ฅผ ๋์ (flex-end)์ผ๋ก ์ ๋ ฌ | |
| center | items ๋ฅผ ๊ฐ์ด๋ฐ ์ ๋ ฌ | |
| baseline | items ๋ฅผ ๋ฌธ์ ๊ธฐ์ค์ ์ ์ ๋ ฌ |

flex-align-items
์์ #
<div class="container"><div class="item">A</div><div class="item">B</div><div class="item">C</div><div class="item">D</div><div class="item">E</div><div class="item">F</div></div>.container {height: 400px;border: 4px solid;display: flex;flex-wrap: wrap;align-items: baseline;}.container .item {width: 120px;height: 100px;background: tomato;border: 4px dashed red;border-radius: 10px;font-size: 30px;}.container .item:nth-child(3n) {font-size: 50px;}flex items#
์์ฑ#
| ์์ฑ | ์๋ฏธ |
|---|---|
| order | flex item ์ ์์๋ฅผ ์ค์ |
| flex | flex-grow , flex-shrink , flex-basis ์ ๋จ์ถ ์์ฑ |
| flex-grow | flex item ์ ์ฆ๊ฐ ๋๋น ๋น์จ์ ์ค์ |
| flex-shrink | flex item ์ ๊ฐ์ ๋๋น ๋น์จ์ ์ค์ |
| flex-basis | flex item ์ (๊ณต๊ฐ ๋ฐฐ๋ถ ์ ) ๊ธฐ๋ณธ ๋๋น ์ค์ |
| align-self | ๊ต์ฐจ ์ถ(cross-axis)์์ item ์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ |
order#
item ์ ์์๋ฅผ ์ค์
item ์ ์ซ์๋ฅผ ์ง์ ํ๊ณ ์ซ์๊ฐ ํด์๋ก ์์๊ฐ ๋ฐ๋ฆฐ๋ค. (์์๊ฐ ํ์ฉ)
โ๏ธ HTML ๊ตฌ์กฐ๋ณด๋ค ์ฐ์ ํด์ ์์๋ฅผ ๋ณ๊ฒฝํ ์ ์๊ธฐ ๋๋ฌธ์ ์ ์ฉorder ์ ์ซ์๊ฐ ๊ฐ์ผ๋ฉด HTML ๊ตฌ์กฐ์ ๋ฐ๋ผ ์ ๋ ฌ๋๋ค
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| ์ซ์ | item ์ ์์๋ฅผ ์ค์ |

flex-order
flex#
item ์ ๋๋น(์ฆ๊ฐ, ๊ฐ์, ๊ธฐ๋ณธ)๋ฅผ ์ค์ - ๋จ์ถ ์์ฑ
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| flex-grow | item ์ ์ฆ๊ฐ ๋๋น ๋น์จ์ ์ค์ | 0 |
| flex-shrink | item ์ ๊ฐ์ ๋๋น ๋น์จ์ ์ค์ | 1 |
| flex-basis | item (๊ณต๊ฐ ๋ฐฐ๋ถ ์ ) ๊ธฐ๋ณธ ๋๋น ์ค์ | auto |
์ฌ์ฉ๋ฒ#
flex: ์ฆ๊ฐ๋๋น ๊ฐ์๋๋น ๊ธฐ๋ณธ๋๋น;.item {flex: 1 1 20px; /* ์ฆ๊ฐ๋๋น ๊ฐ์๋๋น ๊ธฐ๋ณธ๋๋น */flex: 1 1; /* ์ฆ๊ฐ๋๋น ๊ฐ์๋๋น */flex: 1 20px; /* ์ฆ๊ฐ๋๋น ๊ธฐ๋ณธ๋๋น (๋จ์๋ฅผ ์ฌ์ฉํ๋ฉด flex-basis๊ฐ ์ ์ฉ */flex: 1; /* ์ฆ๊ฐ๋๋น */}โ๏ธ flex ๋จ์ถ ์์ฑ์ ์ฌ์ฉํ ๊ฒฝ์ฐ, flex-basis ์ ๊ธฐ๋ณธ๊ฐ์ 0 ์ด๋ค. (๊ฐ๋ณ ์์ฑ์์ฌ์ฉํ๋ฉด auto )
flex-grow#
item ์ ์ฆ๊ฐ ๋๋น ๋น์จ์ ์ค์ .
์ซ์๊ฐ ํฌ๋ฉด ๋ ๋ง์ ๋๋น๋ฅผ ๊ฐ์ง
item ์ด ๊ฐ๋ณ ๋๋น๊ฐ ์๋๊ฑฐ๋, ๊ฐ์ด 0 ์ผ ๊ฒฝ์ฐ ํจ๊ณผ๊ฐ ์๋ค.
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| ์ซ์ | item ์ ์ฆ๊ฐ ๋๋น ๋น์จ์ ์ค์ |

flex-grow
๋ชจ๋ items ์ ์ด ์ฆ๊ฐ ๋๋น( flex-grow )์์ ๊ฐ item ์ ์ฆ๊ฐ ๋๋น์ ๋น์จ๋งํผ๋๋น๋ฅผ ๊ฐ์ง ์ ์๋๋ฐ,
์ฒซ ๋ฒ์งธ ๊ทธ๋ฆผ์ฒ๋ผ item ์ด 3๊ฐ์ด๊ณ ์ฆ๊ฐ ๋๋น๊ฐ ๊ฐ๊ฐ 1 , 2 , 1 ์ด๋ฉด
์ฒซ ๋ฒ์งธ item ์ ์ด ๋๋น์ 25% (1/4),
๋ ๋ฒ์งธ item ์ ์ด ๋๋น์ 50% (2/4),
์ธ ๋ฒ์งธ item ์ ์ด ๋๋น์ 25% (1/4)์ ๊ฐ์ง๊ณ ,
๋ ๋ฒ์งธ ๊ทธ๋ฆผ์ฒ๋ผ item ์ด 3๊ฐ์ด๊ณ ์ฆ๊ฐ ๋๋น๊ฐ ๊ฐ๊ฐ 1 , 3 , 2 ์ด๋ฉด
์ฒซ ๋ฒ์งธ item ์ ์ด ๋๋น์ 16.6% (1/6),
๋ ๋ฒ์งธ item ์ ์ด ๋๋น์ 50% (1/2),
์ธ ๋ฒ์งธ item ์ ์ด ๋๋น์ 33.3% (1/3)๋ฅผ ๊ฐ์ง๋ค.
์์ #
<div class="container"><div class="item item1">1</div><div class="item item2">2</div><div class="item item3">3</div></div>.container {border: 4px solid;display: flex;}.container .item {width: 100px; /* ๋ชจ๋ ์์ดํ
์ ๊ธฐ๋ณธ ๋๋น๊ฐ ์ง์ ๋์ด ์๋ ์ํ */height: 100px;background: tomato;border: 4px dashed red;border-radius: 10px;}.item1 {flex-grow: 1;}.item2 {flex-grow: 2;}โ๏ธ ์์ดํ ์ ๊ธฐ๋ณธ ๋๋น๊ฐ ์ง์ ๋์ด ์๋ ์ํ์ผ ๊ฒฝ์ฐ ์ ์์ ์ฒ๋ผ item1 ๊ณผ item2 ์ flex-grow ๊ฐ์ด 1 , 2 ์ด๋ผ๊ณ ํด์ ์ ํํ๊ฒ 2๋ฐฐ ์ฐจ์ด๊ฐ ๋๋ ๊ฒ์ด ์๋๋ค.
.container {border: 4px solid;display: flex;}.container .item {/* width: 100px; */height: 100px;background: tomato;border: 4px dashed red;border-radius: 10px;}.item1 {flex-grow: 1;}.item2 {flex-grow: 2;}.item3 {width: 100px;}โ๏ธ ์ ์์ ๋ฅผ ์ด๋ ๊ฒ ๋ฐ๊พธ๋ฉด ์ ํํ 2๋ฐฐ ์ฐจ์ด๊ฐ ๋๊ฒ ๋๋ค.ํ์ง๋ง ๊ฐ๋ก ๋๋น๋ฅผ ์ง์ ํ๋ width ์ ์์์ ๊ธฐ๋ณธ ๋๋น๋ฅผ ์ง์ ํด์ฃผ๋ flex-basis ์์ฑ์ ์ํฅ์ ๋ฐ์ ์์๊ธฐ ๋๋ฌธ์ flex-grow ๋ ์๋ฒฝํ๊ฒ 2๋ฐฐ, 3๋ฐฐ์ ํฌ๊ธฐ๋ฅผ ์ง์ ํ๊ธฐ ์ํด ์ฌ์ฉํ๋ ๊ฐ๋ ์ ์๋๊ณ ์ฆ๊ฐ ๋๋น ๋น์จ์ ์ค์ ํ๋ ๊ฐ๋ ์ด๋ค.
.container {border: 4px solid;display: flex;}.container .item {height: 100px;background: tomato;border: 4px dashed red;border-radius: 10px;}.item1 {flex-grow: 1;}.item2 {width: 100px;}๐ก ์ด๋ ๊ฒ ํ item ์ ๊ณ ์ ๋๋น width ๋ฅผ ์ง์ ํ๊ณ ํ item ์ flex-grow ์์ฑ์์ง์ ํ๋ฉด, container ์ ์ฌ์ด์ฆ๊ฐ ๋ณํ ๋ ์ง์ ํ item ๋ง ๊ฐ๋ณ ์ฌ์ด์ฆ๋ฅผ ์ง๋๋๋ก๋ง๋ค ์ ์๋ค.
flex-shrink#
item ์ ๊ฐ์ ๋๋น ๋น์จ์ ์ค์ .
์ซ์๊ฐ ํฌ๋ฉด ๋ ๋ง์ ๋๋น๊ฐ ๊ฐ์
item ์ด ๊ฐ๋ณ ๋๋น๊ฐ ์๋๊ฑฐ๋, ๊ฐ์ด 0 ์ผ ๊ฒฝ์ฐ ํจ๊ณผ๊ฐ ์๋ค.
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| ์ซ์ | item ์ ๊ฐ์ ๋๋น ๋น์จ์ ์ค์ | 1 |

flex-shrink
โ๏ธ ์ค๋ฅธ์ชฝ ๊ทธ๋ฆผ์ฒ๋ผ ๊ธฐ๋ณธ ๋๋น( flex-basis )์ ํฌ๊ธฐ์ ๋ฐ๋ผ ๋น์จ ๊ณ์ฐ์ด ๋ฌ๋ผ์ง๋ค.
flex-basis#
item ์ (๊ณต๊ฐ ๋ฐฐ๋ถ ์ ) ๊ธฐ๋ณธ ๋๋น๋ฅผ ์ค์ .
๊ฐ์ด auto ์ผ ๊ฒฝ์ฐ width , height ๋ฑ์ ์์ฑ์ผ๋ก item ์ ๋๋น๋ฅผ ์ค์ ํ ์์๋ค.
ํ์ง๋ง ๋จ์ ๊ฐ์ด ์ฃผ์ด์ง ๊ฒฝ์ฐ ์ค์ ํ ์ ์๋ค.
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| auto | ๊ฐ๋ณ item ๊ณผ ๊ฐ์ ๋๋น | auto |
| ๋จ์ | px , em , cm ๋ฑ ๋จ์๋ก ์ง์ |
โ๏ธ flex ๋จ์ถ ์์ฑ์์ flex-basis ๋ฅผ ์๋ตํ๋ฉด ๊ฐ์ด 0 ์ด ๋๋ค.

flex-basis
โ๏ธ item ์ ์ฒด๊ฐ ๋น์จ๋๋ก( flex-grow ) ์ฆ๊ฐํ๋ ค๋ฉด flex-basis ๊ฐ 0 ์ธ ๊ฒ์ด ์ค์ํ๋ค.
์์ #
<div class="container"><div class="item item1">Good job!</div><div class="item item2">A</div><div class="item item3">Hello world!</div></div>.container {border: 4px solid;display: flex;}.container .item {height: 100px;background: tomato;border: 4px dashed red;border-radius: 10px;flex-grow: 1;flex-basis: 0;}โ๏ธ flex-basis: auto; ์ด๋ฉด ์ฝํ ์ธ ๋ฅผ ์ ์ธํ ์์ญ์ ๋น์จ์ ๋ฐ๋ผ item ์ ๋๋น๊ฐ ์ค์ ๋๋ค. flex-basis: 0; ์ด๋ฉด item ์ ์ฒด๊ฐ ๋น์จ์ ๋ฐ๋ผ ์ค์ ๋๋ค.
align-self#
๊ต์ฐจ ์ถ(cross-axis)์์ ๊ฐ๋ณ item ์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์
align-items ๋ container ๋ด ๋ชจ๋ item ์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ ํ๋๋ฐ, ํ์์ ์ํด ์ผ๋ถ item ๋ง ์ ๋ ฌ ๋ฐฉ๋ฒ์ ๋ณ๊ฒฝํ๋ ค๊ณ ํ ๊ฒฝ์ฐ align-self ๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
์ด ์์ฑ์ align-items ์์ฑ๋ณด๋ค ์ฐ์ ํ๋ค.
์์ฑ ๊ฐ#
| ๊ฐ | ์๋ฏธ | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|
| auto | Container ์ align-items ์์ฑ์ ์์๋ฐ์ | auto |
| stretch | Container ์ ๊ต์ฐจ ์ถ์ ์ฑ์ฐ๊ธฐ ์ํด item์ ๋๋ฆผ | |
| flex-start | item ์ ๊ฐ ์ค์ ์์์ (flex-start)์ผ๋ก ์ ๋ ฌ | |
| flex-end | item ์ ๊ฐ ์ค์ ๋์ (flex-end)์ผ๋ก ์ ๋ ฌ | |
| center | item ์ ๊ฐ์ด๋ฐ ์ ๋ ฌ | |
| baseline | item ์ ๋ฌธ์ ๊ธฐ์ค์ ์ ์ ๋ ฌ |

flex-align-self
Reference#
ํจ์คํธ์บ ํผ์ค - ํ๋ก ํธ์๋ ๊ฐ๋ฐ ๊ฐ์ - HTML & CSS, SASS(SCSS) Part by ParkYoungWoong