1. Flex1.1. ๋ค์ด๊ฐ๊ธฐ์ ์์1.2. Flex๋?1.3. ๋น์ ์ด Flex๋ฅผ ์๋ฉด ๋ง๋ค ์ ์๋ ๊ฒ๋ค : Flex ์์ฑ์ ํตํด ๋ง๋ค ์ ์๋ ๋ ์ด์์ ์๊ฐ1.4. Flex์ ํน์ง1.5. axis์ cross-axis1.5.1. axis๋?1.5.2. ์ฃผ์ถ๊ณผ ๊ต์ฐจ์ถ1.5.3. dir ํน์ฑ1.5.4. writing mode์ ๋ฐ๋ผ ๋ฐ๋๋ ์ถ1.6. ๊ธฐ๋ณธ ์์ฑ ์ ๋ณด1.6.1. Flex ์์๋ณด๊ธฐ2. Flex-direction2.1. flex-direction : row2.2. flex-direction : row-reverse2.3. flex-direction : column2.4. flex-direction : column-reverse3. Justify-content3.1. flex-start3.2. flex-end3.3. center3.4. space-between, space-around, space-evenly3.4.1. space-between3.4.2. space-around3.4.3. space-evenly3.5. ์์ฃผ ์ฌ์ฉํ์ง ์๋ ์์ฑ๋ค3.5.1. justify-content : normal3.5.2. justify-content : initial3.5.3. justify-content : inherit3.5.4. justify-content : revert3.5.5. justify-content : unset3.5.6. firefox์์๋ง ์ง์ํ๋ ์์ฑ4. Align-items, Align-content4.1. align-items4.2. align-content5. Flex-wrap5.1. flex-wrap : nowrap5.2. flex-wrap : wrap5.3. flex-wrap : wrap-reverse6. Flex-basis6.1. flex-basis๋?6.2. flex-basis์ ๋ค์ด๊ฐ๋ ๊ฐ6.3. flex-basis์ ์ ์ฐ์ฑ6.4. flex-basis์ width/height์ ๊ด๊ณ6.5. flex-basis : auto; ์ flex-basis : 0;6.6. flex-basis : content;6.7. flex-basis๋ณด๋ค๋ flex ์ถ์ฝ ์์ฑ์! (W3C)6.8. flex-basis ํธํ์ฑ7. Flex-grow7.1. flex-grow๋?7.2. flex-grow ๊ธฐ๋ฅ : ํ์ฅ ๋๋ ๊ณ ์ 7.3. flex-grow ์ฌ์ฉ ์ ์ฃผ์ํ ์ 7.4. flex ์ถ์ฝ ์์ฑ7.5. flex-shrink๋ณด๋ค๋ flex ์ถ์ฝ ์์ฑ์! (W3C)7.6. flex-grow ํธํ์ฑ8. Flex-shrink8.1. Flex-shrink ๋?8.2. Flex-shrink ๊ธฐ๋ฅ: ์ถ์ ๋๋ ๊ณ ์ 8.3. Flex-shrink ์ฌ์ฉ ์ ์ฃผ์ํ ์ 8.4. Flex ์ถ์ฝ ์์ฑ8.5. Flex-shrink๋ณด๋ค๋ Flex ์ถ์ฝ ์์ฑ์! (W3C)8.6. Flex-shrink ํธํ์ฑ (caniuse)9. ๊ทธ ๋ฐ์ Flex-item์ ์ฌ์ฉํ๋ ์์ฑ๋ค9.1. align-self9.2. order9.3. z-index10. IE ์ง์์ ์ํ Flex10.1. -ms- prefix ์ฌ์ฉ ์์10.2. IE์์์ Flex ์ด์11. ์ฑ๋ฐฐ ๋ ์ด์์ ๊ทธ๋ฆฌ๊ธฐ11.1. Flex ์์ฑ์ ์ด์ฉํ์ฌ ๊ธฐ๋ณธ ์ฑ๋ฐฐ ๋ ์ด์์ ๊ตฌํํ๊ธฐ11.2. Flex ์์ฑ์ ์ด์ฉํ์ฌ ๋ณํ๋ ์ฑ๋ฐฐ ๋ ์ด์์ ๊ตฌํํ๊ธฐ
ย
ย
ย
1. Flex
1.1. ๋ค์ด๊ฐ๊ธฐ์ ์์
๊ธฐ๊ธฐ๊ฐ ๋ค์ํด์ง์ ๋ฐ๋ผ ํ๋ฉด ํฌ๊ธฐ๋ ๋ค์ํ๊ฒ ๋ณํ๋์๋ค. ๋ค์ํ ๊ธฐ๊ธฐ์ ๋์ํ๊ธฐ ์ํด ์น ์๋น์ค๋ฅผ ์ ์ฐํ๊ฒ ๋ง๋๋ ๊ฒ์ ์ ํ์ด ์๋ ํ์๊ฐ ๋์๋ค.
๋ค์ํ ํ๋ฉด์ ํฌ๊ธฐ์ ๋ง์ถ์ด ์ ์ฐํ๊ฒ ๋์ํ ์ ์๋ ๋ ์ด์์์ ๋ง๋ค๊ธฐ ์ํด ์๋กญ๊ฒ ์ถ๊ฐ๋ ์์ฑ์ด Flex์ Grid์ด๋ค. Flex๋ย 1์ฐจ์ ์ ์ธ ๋ ์ด์์์ ์ก์ ๋ ์ฌ์ฉํ๋ฉฐ, grid๋ย 2์ฐจ์ ์ ์ธ ๋ ์ด์์์ ์ก์ ๋ ์ฉ์ดํ๋ค.
Flex๋ ๋ถ๋ชจ ์์(์ปจํ
์ด๋) ์๋์์ย ์์ ์์(์์ดํ
)๋ค์ด ํ ๋ฐฉํฅ์ผ๋ก ๋ฐฐ์น๊ฐ ๋๋ค. ๋ฐ๋ผ์ ํ ๋๋ ์ด ํ ๊ฐ์ง ๋ฐฉํฅ์ผ๋ก ๋ ์ด์์์ ๋ฐฐ์นํด์ผ ํ๋ ๊ฒฝ์ฐ์ ์ฌ์ฉํ๋ค. ๋ํ ๋ค์ํ ์์ฑ์ ํตํด ์์ ์์ ์ฌ์ด๋ฅผ ์ผ์ ํ ๊ฐ๊ฒฉ์ผ๋ก ์ค ์ ์๊ณ ์ ๋ ฌํ๊ธฐ๊ฐ ๋งค์ฐ ํธํ๋ค.
Grid๋ ํ๊ณผ ์ด Matrix ํํ๋ก ๋ ์ด์์์ ๋ฐฐ์นํด์ผ ํ๋ ๊ฒฝ์ฐ ์ฌ์ฉํ๋ค. ์ํ๋ ์์๋ฅผ ์ด๋์๋ถํฐ ์ด๋๊น์ง, ์ด๋ ๋ฐฉํฅ์ผ๋ก ์ฐจ์งํ๊ฒ ํ ๊ฑด์ง ์ ํ๊ณ ๋ฐฐ์นํ๋ฉด ๋๋ค.
์ง๊ธ๋ถํฐ โ์์์ ์ ๋ฑ ๊น๋ํ๊ณ ์ผ์ค ์๊ฒโ Flex๋ฅผ ๋ฐฐ์๋ณด์.
1.2. Flex๋?
๊ฐ์ ์ด๋ฏธ์ง๋ก grid๋ ์ค๋ช
ํ๋ ๋น๊ตํด๋ณด๋ฉด์ ๋ณด๊ธธ ๊ถํ๋ค. ์ฒซ๋ฒ์งธ ์ด๋ฏธ์ง์ ์๋ ๋นจ๊ฐ์ ๋ฐ์ค๋ฅผ ๋ชจ๋ flex๋ก ๊ตฌํํ ์ ์๋ค.
1.3. ๋น์ ์ด Flex๋ฅผ ์๋ฉด ๋ง๋ค ์ ์๋ ๊ฒ๋ค : Flex ์์ฑ์ ํตํด ๋ง๋ค ์ ์๋ ๋ ์ด์์ ์๊ฐ
์นด๋๋ฅผ ์์๋๋ก ๋ฐฐ์นํ ์ ์๊ณ , ๊ฐ ์นด๋ ๋ด๋ถ์์ Flex๋ฅผ ์ด์ฉํด์ ์์๋ฅผ ๋ณด๋ค ์ฝ๊ฒ ๋ฐฐ์นํ ์ ์๋ค.
ย
Flex๋ฅผ ํ์ฉํ ํํ์ด์ง๋ค. ์ ์ฒด์ ์ธ ๋ ์ด์์์ Flex๋ก ๋ฐฐ์นํ๊ณ , ์์ดํ
๋ค ๋ํ Flex๋ฅผ ์ฌ์ฉํ ๊ฒ์ ํ์ธํ ์ ์๋ค. ์ด์ฒ๋ผ Flex๋ฅผ ์ฌ์ฉํ๋ค๋ฉด, ๊ธฐ์กด์ float๋ฅผ ์ด์ฉํ ๋ฐฉ๋ฒ๋ณด๋ค ๋์ฑ ์ฝ๊ณ ๊ฐํธํ๊ฒ ์์๋ค์ ๋ฐฐ์นํ ์ ์๋ค.
ย
1.4. Flex์ ํน์ง
Flex๋ ๋ถ๋ชจ์ ์์ ํ๊ทธ๊ฐ ํ์ํ๊ณ , ๋ถ๋ชจ ์์(
flex-container
)์ ์์ ์์(flex-item
)์ ์ ์ฉํ๋ ์์ฑ์ด ๊ตฌ๋ถ๋์ด ์๋ค.์ด๋ ์์ฑ์ ์ํฅ์ ์ปจํ
์ด๋์ ์ง๊ณ์์๊น์ง๋ง ์ํฅ์ ์ค๋ค๋ ํน์ง์ด ์์ผ๋ ์ฃผ์ํด์ผ ํ๋ค.
flex-container์๋ ์ ๋ ฌ ๋ฐฉ์๊ณผ item์ ๋ฐฐ์น ํ๋ฆ์ ์ ์ํ๊ณ , flex-item์๋ ํฌ๊ธฐ, ์์ฑ, ์์๋ฅผ ์ ์ํ๋ค.
flex-container
์ ์์ฑ : flex-direction, flex-wrap, justify-content, align-items, align-content ๋ฑ
flex-item
์ ์์ฑ : flex, flex-grow, flex-shrink, flex-basis, align-self, order, z-index ๋ฑ
ย
ใ
ค | ๊ธฐ๋ณธ ์์ฑ | ์ ์ฉ ๋์ |
flex-direction | row | flex containers |
justify-content | normal | flex containers |
align-items | normal | all elements |
align-content | normal | multi-line flex containers |
flex-wrap | nowrap | flex containers |
flex-basis | auto | flex items |
flex-grow | 0 | flex items |
flex- shrink | 1 | flex items |
์ด๋ ํ ์์ฑ์ ์ ์ฉํด์ผ ํ๋์ง ํท๊ฐ๋ฆฌ๋ ๊ฒฝ์ฐ, ์ปจํ
์ด๋์ flex ์์ฑ์ ์ ์ฉํ ๋ค ํฌ๋กฌ ๊ฐ๋ฐ์ ๋๊ตฌ์ ์คํ์ผ ํญ์ ํ์ธํ๋ฉด ์ข๋ค. ์ฃผ์ํ ์์ฑ ๋ค์ฏ ๊ฐ์ง๋ฅผ GUI ๊ธฐ๋ฅ์ผ๋ก ์ ๊ณตํ์ฌ ์ ์ฉ๋ ๋ชจ์ต์ ํ์ธํด๋ณผ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
ย
1.5. axis์ cross-axis
1.5.1. axis๋?
axis๋ก ์์ ์์์ ์ ๋ ฌ ๋ฐฉํฅ์ ์ ์ดํ ์ ์๋ค. ํ๋ฐฉํฅ, ์ด๋ฐฉํฅ์ผ๋ก ๊ฐ๊ฐ ๋ฐ๋ ๋ฐฉํฅ๋ ์ง์ํ๋ค.
1.5.2. ์ฃผ์ถ๊ณผ ๊ต์ฐจ์ถ
- Main Axis
Flex์ ์ฃผ์ถ์ด ๋๋ main axis์ ๋ฐฉํฅ์
flex-direction
์ด๋ผ๋ ์์ฑ์ ์ํด ๊ฒฐ์ ๋๋ค. ์ด๋ ๋ค์๊ณผ ๊ฐ์ด ๋ค ๊ฐ์ง์ ๊ฒฝ์ฐ๊ฐ ์๋ค.flex-direction
ย ์์ฑ์ย row-reverse
ย ๋๋ย column-reverse
ย ๊ฐ์ ์ฌ์ฉํ๋ฉด DOM ๊ตฌ์กฐ์ ์๊ฐ์ ํํ์ ์ฐจ์ด๊ฐ ๋ฐ์ํ์ฌ ์คํฌ๋ฆฐ ๋ฆฌ๋๋ก ์ ๊ทผํ๋ ์ฌ์ฉ์์๊ฒ ์๋ชป๋ ์ ๋ณด๋ฅผ ์ ๋ฌ ํ ๊ฐ๋ฅ์ฑ์ด ์์ผ๋ ์ฃผ์๋ฅผ ์ํ๋ค.flex-direction: row
:flex-direction
์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์์ดํ ๋ค์ด ํ ๋ฐฉํฅ, ๊ฐ๋ก๋ก ๋ฐฐ์น๋๋ค.
flex-direction: row-reverse
: ์์ดํ ๋ค์ด ์ญ์์ผ๋ก ๊ฐ๋ก๋ก ๋ฐฐ์น๋๋ค.
flex-direction: column
: ์์ดํ ๋ค์ด ์ด ๋ฐฉํฅ์ผ๋ก, ์ธ๋ก๋ก ๋ฐฐ์น๋๋ค.
flex-direction: column-reverse
: ์์ดํ ๋ค์ด ์ญ์์ผ๋ก ์ธ๋ก๋ก ๋ฐฐ์น๋๋ค.
ย
ย
- Cross Axis
Cross axis๋ Main axis ๋ฐฉํฅ์ ์์ง ๋ฐฉํฅ์ด๋ค. Main axis๊ฐ
flex-direction
์ ์ํด ๊ฒฐ์ ๋์๋ค๋ฉด, Cross axis๋ main axis ๋ฐฉํฅ์ ๋ฐ๋ผ ๊ฒฐ์ ์ด ๋๋ค. 1.5.3. dir ํน์ฑ
flex๋ฅผ ์ฒ์ ํด๋ณธ๋ค๋ฉด 1.5.3 ์ฑํฐ์ 1.5.4 ์ฑํฐ๋ ๊ฑด๋ ๋ฐ๊ณ ํ์ํ ๋ ์ฐพ์๋ณด๊ธฐ๋ฅผ ๊ถ๊ณ ํ๋ค.
html ์์ ํ
์คํธ์ ๋ฐฉํฅ์ฑ์ ๋ํ๋ด๋ ์ด๊ฑฐ๋ ์์ฑ์ด๋ค. ๊ธฐ๋ณธ๊ฐ์
auto
์ด๋ค.<div dir = "ltr / rtl / auto"> ... </div>
ltr
: ๊ธ์๋ฅผ ์ฝ๋ ๋ฐฉ๋ฒ์ด ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ์ฐ์ด๋ ์ธ์ด์ด๋ค.
rtl
: ๊ธ์๋ฅผ ์ฝ๋ ๋ฐฉ๋ฒ์ด ์ค๋ฅธ์ชฝ์์ ์ผ์ชฝ์ผ๋ก ์ฝ๋ ์๋๊ถ ๊ตญ๊ฐ์์ ์ฌ์ฉ๋๋ค.
auto
: ๊ธฐ๋ณธ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ์ฌ ๊ฐํ ๋ฐฉํฅ์ฑ์ ๊ฐ์ง ๋ฌธ์๋ฅผ ์ฐพ์ ๋๊น์ง ์์ ๋ด๋ถ์ ๋ฌธ์๋ฅผ ๊ตฌ๋ฌธ ๋ถ์ํ๊ณ ์ ์ฒด ์์์ ํด๋น ๋ฐฉํฅ์ฑ์ ์ ์ฉํ๋ค.
ย
dir ์์ฑ์ ๋ฐ๋ฅธ flex-Axis์ ๋ณํ
flex-direction:row
์ flex-direction:row-reverse
๋ ์ปจํ
์ด๋์ ๋ฐฉํฅ์ฑ์ ๋ฐ๋ผ ์ํฅ์ ๋ฐ๊ธฐ ๋๋ฌธ์ dir
์ ์ญ ์์ฑ์ ํ์ธํด์ผ ํ๋ค.ย
- ltr
flex-direction:row
: flex-Axis๋ ์ผ์ชฝ์ flex-start์์ ์ค๋ฅธ์ชฝ flex-end์ด๋ค.flex-direction:row-reverse
: flex-Axis๋ ์ค๋ฅธ์ชฝ flex-start์์ ์ผ์ชฝ flex-end์ด๋ค.- container์
dir="ltr"
์ ๋ ฅ
- rtl
flex-direction:row
: flex-Axis๋ ์ค๋ฅธ์ชฝ์ flex-start์์ ์ผ์ชฝ flex-end์ด๋ค.flex-direction:row-reverse
: flex-Axis๋ ์ผ์ชฝ flex-start์์ ์ค๋ฅธ์ชฝ flex-end์ด๋ค.- container์
dir="rtl"
์ ๋ ฅ
<body> <div dir="rtl" class="container"> //container๊ฐ rtl๋ก ๋ณํ๋๋ค. <div class="item">1</div> <div class="item even">2</div> <div class="item">3</div> </div> </body>
ย
flex-direction:row
.container { display: flex; flex-direction: row; align-items: flex-start; }
ย
flex-direction:row-reverse
.container { display: flex; flex-direction: row-reverse; align-items: flex-start; }
ย
1.5.4. writing mode์ ๋ฐ๋ผ ๋ฐ๋๋ ์ถ
- writing mode(์ฝ๊ธฐ ๋ชจ๋)๋?
๋ฌธ์๋ฅผ ๊ตฌ์ฑํ๋ ํ
์คํธ ํ๋ฆ ๋ฐฉํฅ์
writing mode
๋ผ๊ณ ํ๋ค. ย
- writing mode์ ์ค์์ฑ
์ต๊ทผ
flex
๋ฐ์ค์ grid
ํ
ํ๋ฆฟ์ ์ฌ์ฉํ ๋ ์ด์์์ด ๋ง์์ง๊ณ ์๋ค. ์ด๋ ์ฐ๋ฆฌ๋ ์์ฐ์ค๋ฝ๊ฒ ์ธ๋ผ์ธ ๋ฐฉํฅ(ํ
์คํธ ๋ฐฉํฅ)์ ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ, ๋ธ๋ก ๋ฐฉํฅ(๋จ๋ฝ ๋ฐฉํฅ)์ ์์์ ์๋๋ผ๊ณ ์๊ฐํ๋ค. ํ์ค ๋ฐฉํฅ row
๋, ์ธ๋ผ์ธ ๋ฐฉํฅ์ด ๊ฐ๋ก์ธ ๊ฒ๋ ์ด์ํ๋ค๊ณ ๋๋ผ์ง ์๋๋ค. ํ์ง๋ง ๊ตญ๊ฐ๋ง๋ค ์ค์ ๋ writing mode
๊ฐ ๋ค๋ฅผ ์ ์๋ค. ๋ง์ฝ ์ฐ๋ฆฌ๊ฐ ๋ง๋ ํํ์ด์ง๋ฅผ ์ ์ธ๊ณ์์ ๋ณด๊ฒ ๋๋ค๋ฉด,
writing mode
๋ฅผ ๊ณ ๋ คํด์ผ ํ๋ ์ํฉ์ด ์๊ธธ ์๋ ์๋ค. ์์ง์ ์์ด๊ถ ๊ตญ๊ฐ์์ ์ฌ์ฉํ๋ horizontal-tb
๋ฐฉํฅ ์ด์ธ์ writing mode๋ฅผ ๋ง์ด ์ฌ์ฉํ์ง ์์ง๋ง, flex
์ grid
์๋๋ฅผ ๋ง์ดํ๋ฉฐ writing mode
์ ๋ํ ์ดํด๋ฅผ ๋ฐํ์ผ๋ก ๋
ผ๋ฆฌ์ ์ฌ๊ณ ๋ฅผ ํ์ฅํ๋ ๊ฒ์ ์ค์ํ ์ผ์ด๋ค.ย
ย
writing mode ์ข
๋ฅ
- horizontal-tb
ํ
์คํธ๋ฅผ ์ผ์ชฝ์์ ์์ํ์ฌ ์ค๋ฅธ์ชฝ์ผ๋ก ์์ฑ๋๋ค. ์์ด๋ ์๋์ด์์ ์ฃผ๋ก ์ฌ์ฉ๋๋ค.
- vertical-rl
ํ
์คํธ๊ฐ ์ค๋ฅธ์ชฝ์์ ์ผ์ชฝ์ผ๋ก ์ธ๋ก๋ก ์์ฑ๋๋ค. ํ๊ตญ, ์ผ๋ณธ, ์ค๊ตญ ๋ฑ์ ์์์๊ถ ๊ตญ๊ฐ์์ ์ธ๋ก ๋ฐฉํฅ์ผ๋ก ๊ธ์ ์์ฑํ ๋์๋ง ์ ์ฉ๋๋ค.
- vertical-lr
ํ
์คํธ๊ฐ ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ์ธ๋ก๋ก ์์ฑ๋๋ค. ๋ํ์ ์ผ๋ก ๋ชฝ๊ณจ์ด๊ฐ ์๋ค.
- sideways-lr, side-rl
horizontal-tb ์์ฑ์ฒ๋ผ ํ
์คํธ๊ฐ ๊ฐ๋ก๋ก ์์ฑ๋๋ค. ํ์ง๋ง
lr
์ rl
๋ฐฉํฅ ๋ณํ๋ ํ์ด์ดํญ์ค์์๋ง ํ์ธ ๊ฐ๋ฅํ๋ค.writing mode์ ๋ฐ๋ผ ๋ฐ๋๋ axis ๋ฐฉํฅ
1) flex-direction: row
horizontal-tb
์ธ๋ผ์ธ๊ณผ ๋ธ๋ก ๋ฐฉํฅ์ด ๋ชจ๋ ๊ฐ๋ก์ด๋ฉฐ,
Main Axis
๋ ๊ฐ๋ก, Cross Axis
์ธ๋ก์ด๋ค. ย
.container { writing-mode: horizontal-tb; }
<div class="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> </div>
ย
ย
vertical-lr
์ธ๋ผ์ธ ๋ฐฉํฅ๊ณผ ๋ธ๋ก ๋ฐฉํฅ์ด ๋ชจ๋ ์ธ๋ก์ด๋ฉฐ
Main Axis
๋ ์ธ๋ก, Cross Axis
๋ ๊ฐ๋ก์ด๋ค. ๊ธ์จ๊ฐ ๋ํ์ง๋ ์ด์ ๋ writing mode๊ฐ ์ ํ๋๋ฉด์ ์ธ๋ผ์ธ๊ณผ ๋ธ๋ก ๋ฐฉํฅ์ด ๋ชจ๋ ์ธ๋ก๋ก ๋ฐ๋์๊ธฐ ๋๋ฌธ์ด๋ค.ย
.container { writing-mode: vertical-lr; }
<div class="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> </div>
ย
ย
2) flex-direction: column
horizontal-tb
์ธ๋ผ์ธ ๋ฐฉํฅ์ ๊ฐ๋ก, ๋ธ๋ก ๋ฐฉํฅ์ ์ธ๋ก์ด๋ฉฐ
Main Axis
๋ ์ธ๋ก, Cross Axis
๊ฐ๋ก์ด๋ค. ย
.container { flex-direction: column; writing-mode: horizontal-tb; }
<div class="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> </div>
ย
ย
vertical-lr
์ธ๋ผ์ธ ๋ฐฉํฅ์ ์ธ๋ก, ๋ธ๋ก ๋ฐฉํฅ์ ๊ฐ๋ก์ด๋ฉฐ Main Axis๋ ๊ฐ๋ก, Cross Axis๋ ์ธ๋ก์ด๋ค.
row
์ verticla-lr
๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ์ธ๋ก ์ฐ๊ธฐ๋ก ์ ํ๋์ด ๊ธ์จ๊ฐ ๋ํ์ง๊ฒ ๋ณด์ธ๋ค.ย
.container { flex-direction: column; writing-mode: vertical-lr; }
<div class="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> </div>
ย
1.6. ๊ธฐ๋ณธ ์์ฑ ์ ๋ณด
1.6.1. Flex ์์๋ณด๊ธฐ
Flex๋ ์์์์(์์ดํ
)์ด ๊ทธ ์์์์(์์ดํ
)์ ํฌํจํ๋ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ๊ณต๊ฐ์ ๋ง์ถฐ ๊ทธ ํฌ๊ธฐ๋ฅผ ์ค์ด๊ฑฐ๋, ๋์ด๊ณ ๋๋ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ๋ง์ถฐ ๊ทธ ์ ๋ ฌ์ ๋ง์ถ๋ css display์ ํ๋์ ์์ฑ์ด๋ค. flex๋ฅผ ๋ณด์ฌ์ฃผ๋ ๊ฐ๋จํ ์๋ก ์ดํด๋ณด์.
<body> <div class="container"> <div class="item">1</div> <div class="item even">2</div> <div class="item">3</div> <div class="item even">4</div> <div class="item">5</div> </div> </body>
ย
ย
์ฌ๊ธฐ์ display: flex๋ฅผ ๋ฃ๋๋ค๋ฉด ์๋์ ๊ฐ์ด ์ ๋ ฌ๋๋ค.
ย
.container { display: flex; }
<body> <div class="container"> <div class="item">1</div> <div class="item even">2</div> <div class="item">3</div> <div class="item even">4</div> <div class="item">5</div> </div> </body>
์์์์(์์ดํ
)๋ค์ด ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ๋ง๊ฒ ์ ๋ ฌ๋ ๋ชจ์ต์ ๋ณผ ์ ์๋ค. ์ด๋ ๊ฒ flex๋ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ๊ณต๊ฐ์ ๋ง๊ฒ ์์์์(์์ดํ
)๋ค์ ํฌ๊ธฐ๋ ์ ๋ ฌ์ ๋ง์ถฐ์ฃผ๋ ์์ฑ์ด๋ค. display์ ๋ํ์ ์ธ ์์ฑ ๊ฐ์ grid, block, inline, line-block์ด๋ค.
2. Flex-direction
flex-direction
์ด๋ flex container ๋ด์ item๋ค์ ์ ๋ ฌ ๋ฐฉํฅ์ ๊ฒฐ์ ํ๋ ์์ฑ์ด๋ค. flex-direction
์ ์์์์(์์ดํ
)์ ๋ถ๋ชจ์์์ธ (์ปจํ
์ด๋)์ ์ ์ฉํ์ฌ ์ฌ์ฉํ๋ฉฐ ์ข
๋ฅ๋ row
, row-reverse
, column
, column-reverse
๋ค ๊ฐ์ง๊ฐ ์๋ค.2.1. flex-direction : row
์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ๊ธ์จ๊ฐ ์จ์ง๋ ํ ๋ฐฉํฅ ์ ๋ ฌ์ด๋ฉฐ,
flex-direction
์ ๋ฐ๋ก ์ค์ ํ์ง ์์ผ๋ฉด ์ด๊น๊ฐ์ผ๋ก ์ค์ ๋๋ค. .container { display: flex; flex-direction: row; }
2.2. flex-direction : row-reverse
row
์ ๋์ผํ๊ฒ ๋ณด์ฌ์ง์ง๋ง ์์์ ๊ณผ ๋์ ์ด ๋ฐ๋๋ก ์์นํ๋ค..container { display: flex; flex-direction: row-reverse; }
์ปจํ
์ด๋ ๋ด์ ์์นํ ์์ดํ
๋ค์ ์ ์ฐํ๊ฒ ์ ๋ ฌ ํ ์ ์์ผ๋ฉฐ, ์ญ์์ผ๋ก ์ ๋ ฌํ๋ค. ์ปจํ
์ด๋์๊ฒ
display: flex
์์ฑ์ ๋ถ์ฌํ์ง ์์ผ๋ฉด ์์ดํ
์ ์ ์ฐํ๊ฒ ์์ง์ด์ง ์๋๋ค.2.3. flex-direction : column
Flex ๋ด box๋ค์ ์์ง์ผ๋ก ์ ๋ ฌํ๋ค. ์ปจํ
์ด๋ ๋ด๋ถ์ ์์๋ค์ด ์์ดํ
์ด ์๋ ๊ฒฝ์ฐ ํด๋น ์์ฑ์ ๊ฐ์ ์ ์ฉ๋์ง ์๋๋ค.
flex-direction : column;
์ผ ๋ ์ฃผ์ถ์ ์ธ๋ก ๋ฐฉํฅ์ด ๋๊ณ , ๊ต์ฐจ ์ถ์ ๊ฐ๋ก ๋ฐฉํฅ์ด ๋๋ค. ์์ดํ
์ ์ถ๊ฐํ๋ ๊ฒฝ์ฐ ๋งํฌ์
์์์ ๋ง๊ฒ ์์์ ์๋๋ก ํ๋ฅด๋ฏ์ด ์ ๋ ฌ๋๋ค..container{ display : flex; flex-direction : column; }
2.4. flex-direction : column-reverse
column
๊ณผ ๋์ผํ๊ฒ ๋ณด์ฌ์ง์ง๋ง ์์ ์ ๊ณผ ๋ ์ ์ด ๋ฐ๋๋ก ์์นํ๋ค..container{ display : flex; flex-direction : column-reverse; }
3. Justify-content
justify-content๋ main-axis๋ก ์ด๋ป๊ฒ ์ ๋ ฌํ ์ง ์ ํ๋ ์ฝ๋์ด๋ค.
3.1. flex-start
๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ display: flex, justify-content: flex-start ๊ฐ์ ์ฃผ๋ฉด ๋๋ค.
.container { display: flex; justify-content: flex-start; }
justify-content: flex-start;
๋ ๊ธฐ๋ณธ๊ฐ์ผ๋ก Flex ์์ดํ
๋ค์ ์์์ ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํ๋ค. ๊ธฐ๋ณธ๊ฐ์ผ ๋, ๊ธฐ์ค์ด ๋๋ ์ ์ ์ผ์ชฝ ์ถ์ ์๋จ์ด๋ค.ย
flex-direction: row;
์ธ ๊ฒฝ์ฐ์๋ ๊ฐ๋ก(row=ํ)๋ก ์ ๋ ฌ ํ๋ฉฐ ์ผ์ชฝ ์๋จ์ด ๊ธฐ์ค์ ์ด ๋์ด์ ์ผ์ชฝ ์๋จ๋ถํฐ ์ฐจ๋ก๋๋ก 1, 2, 3๋ฒ ์์ผ๋ก ์์ดํ
์ด ๋ฐฐ์น๋๋ค.๊ทธ๋ ์ง๋ง
flex-direction: column;
์ ์ค ๊ฒฝ์ฐ์๋, ์ปจํ
์ด๋์ ์๋จ์ด ๊ธฐ์ค์ ์ธ ๊ฒ์ ๊ฐ์ง๋ง flex ๋ฐฉํฅ์ด row(ํ)๊ฐ ์๋ column(์ด)์ด๊ธฐ ๋๋ฌธ์ ์ธ๋ก(์ด)๋ก ์์ดํ
์ด ๋ฐฐ์น๋๋ค..container { display: flex; justify-content: flex-start; flex:-direction: column; }
3.2. flex-end
๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ display: flex;, justify-content: flex-end; ๊ฐ์ ์ฃผ๋ฉด ๋๋ค.
.container { display: flex; justify-content: flex-end; }
justify-content: flex-end;
๋ ์์ ์์(์์ดํ
)๋ฅผ ๋งจ ๋์ ์ผ๋ก ๋ฐฐ์นํ๋๋ฐ, ๊ธฐ๋ณธ๊ฐ(์ผ์ชฝ ์ถ)์ ๋ฐ๋์ธ ์ค๋ฅธ์ชฝ ์ถ์ ์๋จ์ด ๊ธฐ์ค์ด ๋๋ค.flex-direction: row;
์ธ ๊ฒฝ์ฐ์ผ ๋์๋ row(ํ)๋ก ์ ๋ ฌํ๊ธฐ ๋๋ฌธ์ ์์ ์์(์์ดํ
)์ธ 1, 2, 3๋ฒ์ ์์ดํ
๋ค์ด ์ค๋ฅธ์ชฝ ์ถ์ ๋ถ์ด ๋ฐฐ์น๋๋ค.flex-direction: column;
์ ์ค ๊ฒฝ์ฐ์๋, flex ๋ฐฉํฅ์ด row(ํ)๊ฐ ์๋ column(์ด)์ด ๋๊ธฐ ๋๋ฌธ์ ์ธ๋ก(์ด)๋ก ์์ ์์(์์ดํ
)๊ฐ ๋ฐฐ์น๋๋ค.๊ทธ๋ฆฌ๊ณ
justify-content: flex-end;
์ ๊ฒฝ์ฐ, ์์ ์์(์์ดํ
)๋ฅผ ๋ฐฐ์นํ๋ ๊ธฐ์ค์ด ๊ธฐ๋ณธ๊ฐ(์๋จ ์ถ)์ ๋ฐ๋์ธ ํ๋จ ์ถ์ด ๋๊ธฐ ๋๋ฌธ์ 1, 2, 3๋ฒ์ ์์ดํ
์ด ์ธ๋ก๋ก ์ ๋ ฌ๋์ด ํ๋จ์ ๋ถ์ด ๋ฐฐ์น๋๋ค..container { display: flex; justify-content: flex-end; flex-direction: column; }
3.3. center
justify-content: center
๋ฅผ ์ค ๊ฒฝ์ฐ, Flex-box ๋ด์ ์์๋ค์ ์ฃผ์ถ(main-axis)์ ์ค์์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํ๋ค. ์ฆ, ์์๋ค์ ๊ฐ์ด๋ฐ ์ ๋ ฌํด์ค๋ค. ์ด๋ ์์์ ๊ฐ๊ฒฉ์ ๊ท ๋ฑ ๋ถํ ๋๋ค. ๊ฐ๋ณ์ ์ผ๋ก ๋น ๊ณต๊ฐ์ ์ ์ดํ๊ณ ์ถ๋ค๋ฉด ํด๋น ์์์ ๋ณ๋์ margin ๊ฐ์ ์ฃผ์ด์ผ ํ๋ค. space-between
,ย space-around
์ญ์ ๋์ผํ๋ค..container { display: flex; justify-content: center; }
.container { display: flex; justify-content: center; align-items:center; }
.container { display: flex; flex-direction:column; justify-content: center; align-items:center; }
3.4. space-between, space-around, space-evenly
๋ค์์ผ๋ก
space-between
, space-around
, space-evenly
์ ๋น์ทํ๋ฉด์๋ ๋ค๋ฅธ ์ ๋ค์ ์์๋ณด์. ์ ์
์ ๊ณตํต์ ์ ์์ ์์๋ค์ ๋ฉ์ธ ์ถ์ผ๋ก ์ ๋ ฌํ๋ฉฐ, ์ผ์ ํ ๊ฐ๊ฒฉ์ ์ค๋ค๋ ๊ฒ์ด๋ค. between, around, evenly์ ๋ป์ ์ฐจ๋ก๋ก โ์ฌ์ด์โ, โ๋๋ ์โ, โ๊ท ๋ฑํ๊ฒโ๋ผ๋ ๋ป์ด๋ค. ๊ทธ๋ผ ๋ป์ ์๊ฐํ๋ฉฐ ์๋ ๊ทธ๋ฆผ์ผ๋ก ์ฐจ์ด์ ์ ํ์ธํด ๋ณด์..container { display: flex; justify-content: flex-start; }
์๋ฌด ์ ๋ ฌ๋ ์ง์ ํด์ฃผ์ง ์์์ ๋์ ๊ธฐ๋ณธ๊ฐ์ด๋ค.
3.4.1. space-between
.container { display: flex; justify-content: space-between; }
justify-content: space-between;
์ ์ฃผ์์ ๋ ์์ ์์๋ค์ โ์ฌ์ด์' ๊ฐ์ ๊ฐ๊ฒฉ์ด ๋ค์ด๊ฐ ๊ฒ์ ๋ณผ ์ ์๋ค. ์ปจํ
์ด๋์ ํจ๋ฉ ๊ฐ์ ์ ์ธํ๋ฉด ์ปจํ
์ด๋์ ๋๋น์ ๊ฝ ์ฐจ๊ฒ ๋ฐฐ์น๋๋ค.3.4.2. space-around
.container { display: flex; justify-content: space-around; }
์์ดํ
์ โ๋๋ ์' ๊ฐ์ ๊ฐ๊ฒฉ์ด ๋ค์ด๊ฐ ๊ฒ์ ๋ณผ ์ ์๋ค. ์์ดํ
์ฌ์ด์๋ ๊ฐ์ ๊ฐ๊ฒฉ์ด 2๋ฒ์ฉ ๋ค์ด๊ฐ๊ฒ ๋๋ฏ๋ก ์ ๋ ์ปจํ
์ด๋ ์ฌ์ด์ ๊ฐ๊ฒฉ์ ์์ดํ
์ฌ์ด์ ๊ฐ๊ฒฉ์ 1/2์ด ๋๋ค.
3.4.3. space-evenly
.container { display: flex; justify-content: space-evenly; }
๋ชจ๋ ๊ฐ๊ฒฉ์ด โ๊ท ๋ฑํ๊ฒ' ๋ฐฐ์น๋ ๊ฒ์ ๋ณผ ์ ์๋ค. space-around์ ๋น์ทํ๊ฒ ๋ณด์ด์ง๋ง ์ ๋์ ๊ฐ๊ฒฉ๊ณผ ์์ ์์ ์ฌ์ด์ ๊ฐ๊ฒฉ์ด ๊ฐ์ ๊ฒ์ ํ์ธํ ์ ์๋ค.
3.5. ์์ฃผ ์ฌ์ฉํ์ง ์๋ ์์ฑ๋ค
3.5.1. justify-content : normal
๊ฐ์ด ์ค์ ๋์ง ์์ ๊ฒ์ฒ๋ผ ๊ธฐ๋ณธ ์์น์ ์ ๋ ฌํ๋ค. ๊ธฐ๋ณธ๊ฐ์ด๋ฏ๋ก ์๋ต ํ ์ ์๋ค.
.container { display: flex; justify-content: normal; align-items: flex-start; }
3.5.2. justify-content : initial
๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ ๋ ฌํ๋ค. justify-content์ ๊ธฐ๋ณธ๊ฐ์ normal์ด๋ฏ๋ก ์์ justify-content:normal๊ณผ ๊ฒฐ๊ณผ๊ฐ ๋์ผํ๊ฒ ๋์จ๋ค.
.container { display: flex; justify-content: initial; align-items: flex-start; }
3.5.3. justify-content : inherit
์์๋๋ ๊ฐ์ ๋ฐ๋ผ ์ ๋ ฌํ๋ค. container์ class ๋ช
์ด โwrap-containerโ์ธ ๋ถ๋ชจ ์์๋ฅผ ๋ง๋ค์ด ์ฃผ์๋ค. wrap-container์ justify-content:center ์์ฑ์ด ์์๋์ด ์์ ์์์ธ container์ justify-content๋ center๋ก ์ ์ฉ๋๋ค.
.wrap-container { display: flex; justify-content: center; } .container { display: flex; justify-content: inherit; }
<body> <div class="wrap-container"> <div class="container"> <div class="item">1</div> <div class="item even">2</div> <div class="item">3</div> </div> </div> </body>
3.5.4. justify-content : revert
์์๋ ์์ฑ์ผ๋ก๋ถํฐ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋๋๋ฆฐ๋ค. ํน์ ์ฌ์ดํธ๋ง์ css ์์ฑ์ด ์ง์ ๋์ด ์๊ฑฐ๋ ์ฌ์ฉ์๊ฐ ์ ์ํ ์คํ์ผ์ด ์ ์ฉ๋ ์์ฑ์ ๋ถ๋ชจ ์์ฑ ๋๋ ์ฌ์ฉ์ ์์ด์ ํธ์ ๊ธฐ๋ณธ ์คํ์ผ๋ก ๋๋๋ฆฐ๋ค. ์ฌ์ฉ์ ์์ด์ ํธ๋ ๋ธ๋ผ์ฐ์ ๋ง๋ค ์ ํด๋์ css ๊ธฐ๋ณธ ๊ท์น์ด๋ค.
3.5.5. justify-content : unset
๋ถ๋ชจ ์์๋ก๋ถํฐ ์์๋ฐ๋ ๊ฐ์ด ์์ผ๋ฉด inherit๋ก ์ ์ฉ๋๊ณ ์์๋๋ ๊ฐ์ด ์๋ค๋ฉด initial ์์ฑ์ผ๋ก ์ ๋ ฌํ๋ค.
3.5.6. firefox์์๋ง ์ง์ํ๋ ์์ฑ
justify-content: revert-layer;
์ด์ ๋ ์ด์ด์ ์ง์ ๋ ์คํ์ผ๋ก ๋๋๋ฆด ์ ์๋ค. revert์ ๋ฌ๋ฆฌ ์์ฑ์ ์๋ณธ์ ์ ์ฉ๋ ์คํ์ผ์ ์ ๊ฑฐํ๊ณ ์ฌ์ฉ์ ์๋ณธ ๋๋ ์ฌ์ฉ์ ์์ด์ ํธ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋๋๋ฆฐ๋ค.
justify-content: safe;
๋ค๋ฅธ ์ ๋ ฌ ์์ฑ๊ณผ ํจ๊ป ์ฌ์ฉ๋๋ค. ํญ๋ชฉ์ด ์ปจํ
์ด๋๋ฅผ ์ค๋ฒํ๋ก ํ์ฌ ๋ฐ์ดํฐ๊ฐ ์์ค๋๋ค๋ฉด ํญ๋ชฉ์ด start ์์ฑ์ฒ๋ผ ์ ๋ ฌ๋๋ค.
justify-content: unsafe;
๋ค๋ฅธ ์ ๋ ฌ ์์ฑ๊ณผ ํจ๊ป ์ฌ์ฉ๋๋ค. ์ปจํ
์ด๋์ ์๋์ ํฌ๊ธฐ์ ๊ด๊ณ์์ด, ๋ฐ์ดํฐ ์์ค์ ์ผ์ผํค๋ ์ค๋ฒํ๋ก๊ฐ ๋ฐ์ํ ์ ์๋์ง์ ๊ด๊ณ์์ด ์ง์ ๋ ์ ๋ ฌ ๊ฐ์ด ์ ์ฉ๋ฉ๋๋ค.
4. Align-items, Align-content
4.1. align-items
align์ ์ฌ์ ์ ์ ์๋ โ์ผ์ง์ ์ผ๋ก ๋ง์ถ๋คโ์ด๋ค. ์ฆ, flex์์ align์ด๋ ์ถ์ ์์ง ๋ฐฉํฅ ์ ๋ ฌ์ ์๋ฏธํ๋ฉฐ, ๋ถ๋ชจ์์(์ปจํ
์ด๋) ์์์ ๊ต์ฐจ ์ถ์ ๋ฐ๋ผ ์์์์(์์ดํ
)๊ฐ ์ ๋ ฌ๋๋ ์์ฑ์ด๋ค.
ย
์์ฑ
- stretch
align-items์ ๊ธฐ๋ณธ๊ฐ์ด๋ค. ๋ถ๋ชจ์์(์ปจํ
์ด๋)์ ๋์ด๋งํผ ์์์์(์์ดํ
) ๋์ด๊ฐ ๊ฐ์ด ๋์ด๋๋ค.
.container { display: flex; align-items: stretch; }
ย
- flex-start
์์์์(์์ดํ
)๋ ๊ต์ฐจ ์ถ ์์์ ์์ ์ ๋ ฌ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ๊ฐ๋ก์ถ์ ์์ง์ ์๋ฏธํ๋ฉฐ, ์์์์(์์ดํ
)๋ ์๋จ์์ ์์ง์ผ๋ก ์ ๋ ฌ๋๋ค.
.container { display: flex; align-items: flex-start; }
ย
- flex-end
์์์์(์์ดํ
)๋ ๊ต์ฐจ ์ถ ๋์ ์์ ์ ๋ ฌ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ๊ฐ๋ก์ถ์ ์์ง์ ์๋ฏธํ๋ฉฐ, ์์์์(์์ดํ
)๋ ํ๋จ์์ ์์ง์ผ๋ก ์ ๋ ฌ๋๋ค.
.container { display: flex; align-items: flex-end; }
ย
- center
์์์์(์์ดํ
)๋ ๊ต์ฐจ ์ถ ์ค์์ผ๋ก ์ ๋ ฌ๋๋ค.
.container { display: flex; align-items: center; }
ย
- baseline
์์์์(์์ดํ
)๋ ๊ต์ฐจ ์ถ์ ๊ธฐ์ค์ ์ ์ ๋ ฌ์ด ๋๋ค. ํ
์คํธ์ ๊ธฐ์ค์ ์ด ์ํ์ ์ ๋ฐ๋ผ ์์ดํ
์ด ์ ๋ ฌ๋๋ค.
.container { display: flex; align-items: baseline; }
ย
3. align-self์ ๋ค๋ฅธ ์ ์?
align-items๋ ๋ถ๋ชจ ์์(์ปจํ
์ด๋) ๋ด์ ์๋ ์์ ์์๋ฅผ ๋์์ผ๋ก ์ ์ฉํ๋ ๋ฐ๋ฉด์, align-self๋ ๋ถ๋ชจ ์์(์ปจํ
์ด๋) ์์์ ํน์ ์์ดํ
๋ง ๊ต์ฐจ ์ถ์ผ๋ก ์ ๋ ฌ๋๋ค. ์ฆ, ํน์ ์์ดํ
์ ์ ๋ ฌ์ ๋ฐ๋ก ํ๊ณ ์ถ๋ค๋ฉด ์ด ์์ฑ์ ์ฌ์ฉํ๋ฉด ๋๋ค.
.container { display: flex; align-items: flex-start; } .third_item { align-self: center; }
ํ๋ ์ค ๋ฐ์ค ์ปจํ
์ด๋์
align-items : flex-start
๋ฅผ ์ ์ฉํ๊ณ โthird_itemโ ์ด๋ฆ์ ๊ฐ์ง ํน์ ์์ดํ
๋ง align-self : center
๋ฅผ ์ ์ฉํ๋ค. ์์ ๊ฐ์ด 3๋ฒ ์์ดํ
๋ง ์ค์์ ๋ ฌ ์์ฑ์ด ์ ์ฉ๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค. 4.2. align-content
align-items
๋ ํ ์ค์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํ์ง๋ง, align-content๋ flex-wrap : wrap;
์ด ์ค์ ๋ ๊ฒฝ์ฐ ๋ ์ค๋ถํฐ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํ๋ค. ์๋ ์์๋ฅผ ๋ณด๋ฉด, ๋ ์ฝ๊ฒ ์ ์ ์๋ค.์ข์ธก์
align-items : center;
, ์ฐ์ธก์ align-content : center;
๋ก ์ ๋ ฌํ ๊ฒฐ๊ณผํ๋ฉด์ด๋ค. align-items๋ ์์ดํ
ํ ์ค๋ง๋ค ์์ฑ์ด ์ ์ฉ๋์๊ธฐ ๋๋ฌธ์ ๋ ์ค ์ฌ์ด์ ๊ฐ๊ฒฉ์ด ์๊ฒจ ์ ๋ ฌ๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ๋ฐ๋ฉด์, align-content๋ ๋ ์ค ์ด์์ ์์ดํ
์ ์์ง์ถ ๋ฐฉํฅ์ผ๋ก ๋ผ์ธ ์์ฒด๋ฅผ ์ ๋ ฌํ๊ธฐ ๋๋ฌธ์ ๋ ์ค ์ฌ์ด์ ๊ฐ๊ฒฉ์ด ์๊ธฐ์ง ์์ ๊ฒ์ ๋ณผ ์ ์๋ค.ย
์์ฑ
- stretch
๋ถ๋ชจ์์(์ปจํ
์ด๋)์ ๋์ด๋งํผ ์์์์(์์ดํ
) ๋์ด๊ฐ ๊ฐ์ด ๋์ด๋๋ค.
.container { display: flex; flex-wrap: wrap; align-content: stretch; }
ย
- flex-start
๋ถ๋ชจ์์(์ปจํ
์ด๋)์ ์ต์๋จ์์๋ถํฐ ์ ๋ ฌ์ ์์ํ๋ค.
.container { display: flex; flex-wrap: wrap; align-content: flex-start; }
ย
- flex-end
๋ถ๋ชจ์์(์ปจํ
์ด๋)์ ์ตํ๋จ์์๋ถํฐ ์ ๋ ฌ์ ์์ํ๋ค.
.container { display: flex; flex-wrap: wrap; align-content: flex-end; }
ย
- center
๋ถ๋ชจ์์(์ปจํ
์ด๋) ๊ต์ฐจ ์ถ์ ์ค์์ ์ ๋ ฌํฉ๋๋ค.
.container { display: flex; flex-wrap: wrap; align-content: center; }
ย
- space-between
๋ถ๋ชจ์์(์ปจํ
์ด๋) ๊ต์ฐจ ์ถ์ ์ ๋(์์์ , ์ข
๋ฃ์ )์ ๋ง์ถฐ ์์ดํ
๊ฐ์ ์ผ์ ํ ๊ฐ๊ฒฉ์ ๋๊ณ ์ ๋ ฌํ๋ค.
.container { display: flex; flex-wrap: wrap; align-content: space-between; }
ย
- space-around
space-between๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ๋ถ๋ชจ์์(์ปจํ
์ด๋) ๊ต์ฐจ ์ถ์ ์ ๋(์์์ , ์ข
๋ฃ์ )์ ๋ง์ถฐ ์์ดํ
๊ฐ์ ์ผ์ ํ ๊ฐ๊ฒฉ์ ๋๊ณ ์ ๋ ฌํ๋ค. ์ด๋ ์ฒซ ์์ดํ
์ ์ฌ๋ฐฑ๊ณผ ๋ง์ง๋ง ์์ดํ
๋ค ์ฌ๋ฐฑ์ ๊ฐ ์์ดํ
๊ฐ ๊ฑฐ๋ฆฌ์ ์ ๋ฐ ํฌ๊ธฐ๋ฅผ ์ฐจ์งํ์ฌ ์ ๋ ฌ๋๋ค.
.container { display: flex; flex-wrap: wrap; align-content: space-around; }
- space-evenly
space-between๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ๋ถ๋ชจ ์์(์ปจํ
์ด๋) ๊ต์ฐจ ์ถ์ ์ ๋(์์์ , ์ข
๋ฃ์ )์ ๋ง์ถฐ ์์ดํ
๊ฐ์ ์ผ์ ํ ๊ฐ๊ฒฉ์ ๋๊ณ ์ ๋ ฌํ๋ค. ์ด๋ ์์ดํ
๊ฐ์ ๊ฑฐ๋ฆฌ, ์ฒซ ์์ดํ
์ ์ฌ๋ฐฑ๊ณผ ๋ง์ง๋ง ์์ดํ
๋ค ์ฌ๋ฐฑ์ ํฌ๊ธฐ๊ฐ ๋ชจ๋ ๋์ผํ๊ฒ ์ ๋ ฌ๋๋ค. ๋ณธ ์์ฑ์ IE, Edge์์๋ ์ง์๋์ง ์๋๋ค.
.container { display: flex; flex-wrap: wrap; align-content: space-evenly; }
5. Flex-wrap
์นํ์ด์ง ๋ ์ด์์์ ๊ตฌ์ฑํ ๋ ๋ถ๋ชจ ์์(์ปจํ
์ด๋) ์์ ์์ ์์(์์ดํ
)๋ค์ด ๋ง์ผ๋ฉด ๊ณ ๋ฏผํ ๋๊ฐ ์๋ค. ์๋ฅผ ๋ค์ด ์์ด ๋จ์ด ์นํ์ด์ง๋ฅผ ๋ง๋ ๋ค๊ณ ๊ฐ์ ํด๋ณด์. ๋จ์ด ์นด๋๋ค์ ํ ์ค์ ๊ธธ๊ฒ ๋ฐฐ์นํ ๊ฒ์ธ์ง ์๋๋ฉด ํ ์ค์ด ์๋ ๋ ์ค ์ด์์ผ๋ก ๋ฐฐ์นํ ์ง ๊ณ ๋ฏผ์ด ๋ค ๋๊ฐ ์๋ค.
.container { display: flex; /* flex-wrap: nowrap; */ /* flex-wrap: wrap; */ /* flex-wrap: wrap-reverse; */ }
<body> <div class="container"> <div class="item">Cat</div> <div class="item even">Mouse</div> <div class="item">Dog</div> <div class="item even">Tiger</div> <div class="item">Monkey</div> <div class="item even">Rabbit</div> </div> </body>
flex-wrap ์์ฑ์ ์ฌ์ฉํ๊ฒ ๋๋ฉด, ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ํฌ๊ธฐ๋งํผ ๋จ์ด ์นด๋๋ค์ ํฌ๊ธฐ๋ฅผ ์กฐ์ ํ ์๋ ์๊ณ , ๋จ์ด ์นด๋๋ค์ ํฌ๊ธฐ๋งํผ ์์ญ์ ์ฐจ์งํ๊ณ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ์์ญ์ ๋ฒ์ด๋๊ฒ ๋๋ฉด ๋จ์ด ์นด๋๋ฅผ ๋ฐ์ผ๋ก ๋ด๋ ค์ ์ ๋ ฌ๋ ํ ์ ์๊ฒ ๋๋ค.
flex-wrap ์์ฑ์ Flex ๋ ์ด์์ ๋ชจ๋์ ํ์ ์์ฑ์ด๋ค. ์ ๋ ฌ๋ ์์๋ค์ ์ด ๋๋น๊ฐ ๋ถ๋ชจ ๋๋น๋ณด๋ค ํด ๋, ์์๋ค์ ๊ฐ์ ์ ์ผ๋ก ํ ์ค๋ก ํ ๊ฒ์ธ์ง ์ฌ๋ฌ ์ค๋ก ํ ๊ฒ์ธ์ง๋ฅผ ์ ์ํ๋ค. ๋ ์ค ์ด์์ธ ๊ฒฝ์ฐ ์๋ก์ด ๋ผ์ธ์ด ์์ผ ๋ฐฉํฅ์ ๊ฒฐ์ ํ๋ ๊ต์ฐจ ์ถ๋ ์ ์๋๋ค. ๊ฐ๋ก์ถ์ ๋ฉ์ธ์ถ์ ์์ง์ธ ์ถ์ด๋ค. ๋ถ๋ชจ ์์์
display:flex;
๋ฅผ ๊ผญ ์์ฑํด์ผํ๋ค.5.1. flex-wrap : nowrap
flex-wrap ์์ฑ ์คย nowrap์ย ์์ฑ์ ๋ํด์ ์์๋ณด์. flex-wrap๋ ์์ฑ์๊ฐ ๋ฐ๋กย ์ค์ ํ์งย ์๋๋ค๋ฉด ๊ธฐ๋ณธ๊ฐ์ธย nowrap์ผ๋ก ์ค์ ๋๋ค. flex-wrap:ย nowrap์ย ์ฌ์ฉํ์์ ๋, ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ดย ์์ ์์(์์ดํ
)์ย ํฌ๊ธฐ๊ฐย ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ย ํฌ๊ธฐ์ ๋ง์ถฐ ์ผ์ ๋น์จ๋งํผ ์ค์ด๋๋ ๊ฒ์ย ํ์ธํ ย ์ ์์ ๊ฒ์ด๋ค.
ํ์ง๋ง, ๊ฒ์์ ํตํด์ wrap์ ์์ฑ์ย ์ฐพ์๋ดค๋ค๋ฉด, ์๋ ๊ทธ๋ฆผ์ฒ๋ผ ๋ถ๋ชจ์์ญ(์ปจํ
์ด๋)์ ๋์ด๊ฐ๋ ๊ทธ๋ฆผ์ ๋ณด์์ ๊ฒ์ด๋ค. ์ด๋ ๊ฒ ๋๋ ์ด์ ๋ 8์ฅ์์ ๋ค๋ฃจ๊ฒ ๋ flex-shrink์ ์์ฑ ๋๋ฌธ์ด๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก flex-shrink์ย ์ด๊น๊ฐ์ย 1๋กย ์ค์ ๋์ด์์ด์ย ์ผ์ ๋น์จ๋งํผ ์ค์ด๋ค๊ฒ ๋๋๋ฐ ์ด ์์ฑ์ 0์ผ๋ก ํ๋ฉด ์๋ ๊ทธ๋ฆผ์ฒ๋ผ ๋ถ๋ชจ์์ญ(์ปจํ
์ด๋)์ ๋์ด๊ฐ๊ฒ ๋๋ค.
๋ฐ๋ผ์ flex-wrap :ย nowrap์ย ์์ ์์(์์ดํ
)์ ์ ์ฒด ํฌ๊ธฐ๊ฐ ๋ถ๋ชจ์์ญ(์ปจํ
์ด๋)์ ๋์ด๊ฐ์ง ์๋๋ค๋ฉด ์๊ธฐ ์์ ์ ํฌ๊ธฐ๋ฅผ ์ ์งํ๊ฒ ๋๊ณ , ๋ถ๋ชจ์์ญ(์ปจํ
์ด๋)์ ๋์ด๊ฐ๊ฒ ๋๋ค๋ฉด ์ผ์ ํ ๋น์จ๋กย ์ค์ด๋ค๊ฒย ๋๋ค. Flex๋ฅผ ์ฌ์ฉํ๋ค ๋ณด๋ฉดย nowrap์ด๋ผ๋ย ์์ฑ์ ์์ฃผ ๋ณผ ์ผ์ ์์ง๋ง, ์ด ์์ฑ์ ์ฌ์ฉํ๋ฉด ์ด๋ป๊ฒ ๋ณํ๋์ง ์์๋๋ ๊ฒ์ด ์ข๋ค.
5.2. flex-wrap : wrap
๋ค์์ผ๋ก flex-wrap ์์ฑ ์ค์ wrap์ ์์ฑ์ ๋ํด์ ์์๋ณด์. Flex-wrap์ wrap์์ฑ์ ๊ฐ ์์ ์์(์์ดํ
)์ ์ด ๋์ด๊ฐ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ๋์ด ๋ณด๋ค ํด ๋, ๋ถ๋ชจ ์์(์ปจํ
์ด๋) ์์ ์์ ์์(์์ดํ
)์ด ๋ค์ด๊ฐ ์ ์๋๋ก ๋ค์ ์ค์ ์ด์ด์ ์ ๋ ฌํด ์ฃผ๋ ์์ฑ์ ๋งํ๋ค.
์์ ๋งํ flex-wrap์์ no-wrap์ ์ฌ์ฉํ๋ฉด ์์ ์์(์์ดํ
)์ ์ด ๋์ด๊ฐ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ๋์ด๋ณด๋ค ํฐ ๊ฒฝ์ฐ ์ ๋ ฌ๋ ์์๋ค์ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ๋์ด์ ๋ง์ถฐ ์๋ ์ถ์ ๋๊ฒ ๋๋ค.
๋ฐ๋ฉด, flex-wrap:wrap์ ๊ฒฝ์ฐ์๋ ์์ ์์(์์ดํ
)์ ๋์ด๋ฅผ ์ ์งํ ์ฑ๋ก ๋ค์ ์ค๋ก ์ด์ด์ ์ ๋ ฌ ๋๊ฒ ํ๋ค. flex-wrap:wrap์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ, ์์ ์์(์์ดํ
)์ ํฌ๊ธฐ์ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ํฌ๊ธฐ์ ๋ฐ๋ผ ๋ค์ ์ค๋ก ์ ๋ ฌ์ด ์ด์ด์ง๊ฒ ๋๋๋ฐ ์ด๋ flex-direction์ ๋ฐฉํฅ์ ๋ฐ๋ฅด๊ฒ ๋๋ค,
๋ง์ฝ flex-direction์ ๋ฐฉํฅ์ด row(ํ)๋ผ๋ฉด row(ํ)์ ๋ง์ถฐ ์ฃผ์ถ์ธ ์ํ์ผ๋กย ์์ ์์(์์ดํ
)๋ค์ด ์ ๋ ฌ ๋๊ฒ ๋๊ณ , ๊ต์ฐจ์ถ์ธ ์์ง์ถ์ผ๋ก ์์ดํ
์ด ์์ด๊ฒ ๋๋ค.
flex-direction์ ๋ฐฉํฅ์ด column(์ด)์ด๋ผ๋ฉด column(์ด)์ ๋ง์ถฐ ์ฃผ์ถ์ธ ์์ง์ผ๋ก ์์ ์์(์์ดํ
)๋ค์ด ์ ๋ ฌ ๋๊ฒ ๋๊ณ , ๊ต์ฐจ์ถ์ธ ์ํ์ถ์ผ๋ก ์์ ์์(์์ดํ
)์ค์ด ์์ด๊ฒ ๋๋ค.
์ด๋ฌํ ์๋ ๋ง์ถค ๊ฐ์ flex-wrap:wrap์ ์ฑ์ง์ ๋ฐ๋ผ์ ํ๋ฉด์ด ์กฐ์ ๋๋ ๊ฒฝ์ฐ(ํนํ ๋ฏธ๋์ด ์ฟผ๋ฆฌ๋ฅผ ๊ตฌํํ๋ ๊ฒฝ์ฐ), ์์ดํ
์ ํฌ๊ธฐ๊ฐ ๋ณํ์ง ์๊ณ ์์น๋ง ์กฐ์ ๋ ์ ์๊ฒ ํ๊ธฐ ์ํด์ ๋ง์ด ์ฌ์ฉํ๊ฒ ๋๋ค.
5.3. flex-wrap : wrap-reverse
flex-wrap : wrap-reverse;
๋ wrap-reverse
: wrap;
๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ์์ ์์(์์ดํ
)๋ค์ด ํ์ํ ๊ฒฝ์ฐ ์ฌ๋ฌ ์ค์ ๊ฑธ์ณ ๋ฐฐ์น๋์ง๋ง, ๋ค๋ฅธ ์ ์ wrap-reverse์ด๊ธฐ ๋๋ฌธ์ ์์ ์์(์์ดํ
) ์์๋ค์ด ์ ๋ ฌ๋๋ ๊ธฐ์ค์ ์ด ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ๋ฐ๋์ด์ ๋ฐฐ์น๋๋ค.์ ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ display: flex๋ฅผ ์ฃผ๊ณ , flex-wrap: wrap-reverse ๊ฐ์ ์ค์ ํ๋ฉด ๋๋ค.
.container { display: flex; flex-wrap: wrap-reverse; }
ย
- flex-wrap: wrap; ๊ณผ flex-wrap: wrap-reverse; ๋น๊ต
.container { display: flex; flex-wrap: wrap; }
display: flex;
์ ๊ฒฝ์ฐ flex-direction: row;
๊ฐ ๊ธฐ๋ณธ๊ฐ์ด๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ flex-wrap: wrap;
์ธ ๊ฒฝ์ฐ์๋ ๋ถ๋ชจ ์์์ธ ์ปจํ
์ด๋์ ์ผ์ชฝ ์ถ์ ์๋จ๋ถํฐ ์์ ์์์ธ ์์ดํ
๋ค์ด ์์ฐจ์ ์ผ๋ก ๋ฐฐ์น๋๋ค. ์ฆ, ๋ฐฐ์น๊ฐ ์์๋๋ ๊ธฐ์ค์ด ์ฃผ์ถ(main-axis)์ main-start ์ง์ ์ด ๋ถ๋ชจ(์ปจํ
์ด๋)์ ์๋จ, ๊ต์ฐจ ์ถ(cross-axis)์ cross-start ์ง์ ์ ๋ถ๋ชจ(์ปจํ
์ด๋) ์ผ์ชฝ์ด ๋๋ค.ํ์ง๋ง,
flex-wrap: wrap-reverse;
์ ๊ฒฝ์ฐ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ํ๋จ์ธ ๋ฐ๋ฅ ํ์ ์ผ์ชฝ์์๋ถํฐ 1, 2, 3โฆ๋ฒ ์์ผ๋ก ์์ดํ
์ด ๋ฐฐ์น ๋๊ณ ๋๋จธ์ง ์์๋ค์ ๊ทธ ํ ์์ ๋ฐฐ์น ๋๋ค. ๋, ์ ์ฒด์ ์ผ๋ก ๋ณด๋ฉด flex-wrap: wrap;
๊ณผ๋ ๋ฐ๋๋ก ์์ ์์(์์ดํ
)๋ค์ด ์ปจํ
์ด๋์ ํ๋จ์ ๋ถ์ด ๋ฐฐ์น ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค..container { display: flex; flex-wrap: wrap-reverse; }
reverse(์ญ์)์ด๊ธฐ ๋๋ฌธ์ ๋ฐฐ์น ๋๋ ๊ธฐ์ค์ ์ด ๋ฐ๋๊ธฐ ๋๋ฌธ์ด๋ค. ์ฆ,
flex-wrap: wrap-reverse;
๋ฅผ ์ฃผ๊ฒ ๋๋ฉด, ์ฃผ์ถ(main-axis)์ main-start ์ง์ ์ด ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ํ๋จ์ด ๋๋ค. ๊ทธ๋์ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ํ๋จ ์ผ์ชฝ์ด ๊ธฐ์ค์ ์ด ๋์ด ์์ ์์๋ค(์์ดํ
๋ค)์ด ์์๋๋ก ๋ฐฐ์น ๋๊ฒ ๋๋ค. ์์์์(์์ดํ
)๋ ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ width์ ๋ง์ถฐ ์ ๋ ฌ๋๊ธฐ ๋๋ฌธ์ ๋ถ๋ชจ์ witdh๋ฅผ ์ค์ด๋ฉด, ๊ฐ ์ค์ ๋ค์ด๊ฐ๋ ์์ดํ
์ ๊ฐ์ ์ญ์ ์๋ ์์์ ๊ฐ์ด ๋ณ๊ฒฝ๋๊ฒ ๋๋ค.๊ทธ๋ฆฌ๊ณ flex-wrap: wrap; ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก, flex-item ์์๋ค์ ํฌ๊ธฐ๋ฅผ ์ปจํ
์ด๋ ํฌ๊ธฐ์ ๋ง์ถฐ ์ค์ด์ง ์๊ธฐ ๋๋ฌธ์, flex-item(์์ ์์)์ด ๋ถ๋ชจ(์ปจํ
์ด๋)์ ๋ค์ด๊ฐ๊ธฐ์ ๋ ๋ง์ ๋ถํผ๋ฅผ ์ฐจ์งํ๊ฒ ๋๋ฉด ์๋ ์ด๋ฏธ์ง์ฒ๋ผ ์์ดํ
๋ค์ด ์ปจํ
์ด๋ ๋ฐ์ผ๋ก ๋์น๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
ย
- flex-direction: column; ๊ฐ์ ์ค ๊ฒฝ์ฐ flex-wrap: wrap-reverse; ๋ ์ด๋ป๊ฒ ๋ ๊น?
display: flex;
๋ฅผ ์ค ๊ฒฝ์ฐ, flex-direction์ ๊ธฐ๋ณธ๊ฐ์ row์ง๋ง, flex-direction: column;
์ ์ค๋ค๋ฉด ์์์ ํ์ธํ ๊ฒ๋ค๊ณผ๋ ๋ค๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์๋ค. flex์ ๋ฐฉํฅ์ด row(ํ)์ด ์๋ column(์ด)์ผ๋ก ๋ณ๊ฒฝ๋๊ธฐ ๋๋ฌธ์ ์ฃผ์ถ(main-axis)์ด ์ํ(๊ฐ๋ก)์ด ์๋ ์์ง(์ธ๋ก) ๋ฐฉํฅ์ด ๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์,
flex-direction: column;
์ธ ์ํ์์ flex-wrap: wrap-reverse;
๋ฅผ ์ฃผ๊ฒ ๋๋ฉด, ์ฃผ์ถ(main-axis)์ main-start ์ง์ ์ด ๋ถ๋ชจ ์์(์ปจํ
์ด๋)์ ์ค๋ฅธ์ชฝ ๋ ์ง์ ์ด ๋๊ณ , ์ค๋ฅธ์ชฝ ๋์ ์ด(column)๋ถํฐ ์์ดํ
์ด ์ฐจ๋ก๋๋ก ๋ฐฐ์น๋๋ค.6. Flex-basis
6.1. flex-basis๋?
flex-basis๋ ์์ ์์(์์ดํ
)์ ์ฌ์ฉํ๋ ์์ฑ์ด๋ค.
.item { flex-basis: auto; /* ๊ธฐ๋ณธ๊ฐ */ }
๋ถ๋ชจ ์์์ธ ์ปจํ
์ด๋์ ์ฃผ ์ถ(main axis)์ด ๋๋ ๋ฐฉํฅ์ผ๋ก flex ์์ดํ
์ ์ด๊ธฐ ํฌ๊ธฐ(default size)๋ฅผ ์ ํด์ค ์ ์๋ค. ์ปจํ
์ด๋์ ์์ดํ
๋ฐฐ์น ๋ฐฉํฅ(
flex-direction
)์ด ๊ฐ๋ก(row) ์ถ์ผ ๊ฒฝ์ฐ ๋์ด๋ฅผ, ์ธ๋ก(column) ์ถ์ผ ๊ฒฝ์ฐ ๋์ด๋ฅผ ์ง์ ํ๋ค.6.2. flex-basis์ ๋ค์ด๊ฐ๋ ๊ฐ
flex-basis์ ๊ฐ์ผ๋ก๋ ์ฐ๋ฆฌ๊ฐ ์ฌ์ฉํ๋ ๊ฐ์ข
๋จ์๊ฐ ๋ค์ด๊ฐ ์ ์๋ค. ๊ธธ์ด๋ฅผ ๋ํ๋ด๋ ๋จ์๋ค์ธย
em
,ย rem
,ย px
์ด๋ ํผ์ผํฐ์ง(%
) ๊ฐ์ด ๋ ์๋ ์๊ณ , content
, min-content
, max-content
, fit-content
, fill
, auto
๋ฑ์ ํค์๋๊ฐ ๋ ์๋ ์๋ค. ์์๋ 0 ์ธ์ ๋ค๋ฅธ ๊ฐ์ ์ฌ์ฉํ ์ ์๋ค.6.3. flex-basis์ ์ ์ฐ์ฑ
flex-basis ์์ฑ์ ์ ์ฐํ(flexible) ํฌ๊ธฐ๋ฅผ ๊ฐ์ง๋ค. ์ฆ, ๊ณ ์ ์ ์ธ width, height ๊ฐ์ ์ง์ ํด ์ค ๋์ ๋ฌ๋ฆฌ ์ถ์ ๋ฐฉํฅ์ ๋ฐ๋ผ, ๋ ๋ด๋ถ ์ฝํ
์ธ ์ ๋ฐ๋ผ ํฌ๊ธฐ๊ฐ ๊ฐ๋ณ์ , ์ ๋์ ์ผ๋ก ๋ณํ ์ ์๋ค.
6.4. flex-basis์ width/height์ ๊ด๊ณ
๊ธฐ๋ณธ๊ฐ auto๋ ํด๋น ์์ดํ
์ width(๋๋ height) ๊ฐ์ ์ฌ์ฉํ๊ฒ ๋๋ค. ๋ง์ฝ width๊ฐ์ด ์๋ค๋ฉด ์ฝํ
์ธ ์ ํฌ๊ธฐ๊ฐ ๊ธฐ๋ณธ์ผ๋ก ์กํ๊ฒ ๋๋ค.
์ ๊ทธ๋ฆผ์์๋ basis์ ๊ฐ์ 100px๋ก ์ค์ ํ๋ค. ์ฝํ
์ธ ์ ํฌ๊ธฐ๊ฐ ์ ์ผ๋ฉด 100px๋ก ์์ดํ
๋ค์ width๊ฐ ๊ฒฐ์ ๋์ง๋ง, ์ฝํ
์ธ ๊ฐ ๋ง์์ง๊ฒ ๋๋ฉด basis๋ณด๋ค ๋์ด์ง๊ฒ ๋๋ค.
๋ฐ๋ฉด, width๊ฐ์ 100px๋ก ์ค์ ํ๊ฒ ๋๋ฉด basis์ ๋ฌ๋ฆฌ ์ปจํ
์ธ ์ ํฌ๊ธฐ๊ฐ ๋ง์์ง๋ฉด ์์ดํ
์ width๋ 100px๋ก ๊ณ ์ ๋๊ณ , ์ปจํ
์ธ ๊ฐ ๋ฐ์ผ๋ก ๋๊ฐ๊ฒ ๋๋ค. ์ด๋ฅผ ๋ฐฉ์งํ๋ ค๋ฉดย
word-wrap: break-word;
ย ๊ฐ์ ์ฃผ๋ฉด ํด๊ฒฐ๋๋ค.๊ธฐ๋ณธ์ ์ผ๋ก flex-basis ์์ฑ์ด width(๋๋ height) ๊ฐ๋ณด๋ค ์ฐ์ ํ๊ฒ ๋๋ค. ์ฆ, width๋ฅผ 100px์ ์ฃผ๊ณ basis๋ฅผ 300px๋ก ์ฃผ๊ฒ ๋๋ฉด basis๊ฐ์ด ์ฐ์ ์๋์ด ์์ดํ
๋ค์ ๊ธฐ๋ณธ๋๋น๊ฐ 300px๋ก ์กํ๊ฒ ๋๋ค. ์ฃผ์ํ ์ ์ ์๋ก ๋ค๋ฅธ ๊ฐ์ผ ๊ฒฝ์ฐ ๊ธฐ๋ณธ์ ์ผ๋ก flex-basis๊ฐ ์ฐ์ ํ์ง๋ง, ๋๊ฐ์ ๊ฐ์ flex-basis์ width(๋๋ height)์ ์ฃผ๊ณ ๋์์ ์ ์ฉํ ๊ฒฝ์ฐ์ width(๋๋ height)์ ์ ์ฉ์ด ์ฐ์ ์๋๋ค๋ ๊ฒ์ด๋ค. ๋ํ, ์ธ์ด๊ฐ ํ๊ธ์ธ์ง ์์ด์ธ์ง์
word-break
๋ฑ ๋ค๋ฅธ ์์ฑ๊ฐ์ ๋ฐ๋ผ flex-basis๋ ์์๊ณผ ๋ค๋ฅด๊ฒ ๋์ํ ์๋ ์๋ค.6.5. flex-basis : auto; ์ flex-basis : 0;
flex-basis: auto;
๊ฐ ๊ธฐ๋ณธ๊ฐ์ด๋ค. ์ด๋๋ ์ง์ ํด ์ค width(๋๋ height) ๊ฐ์ ์ฌ์ฉํ๊ฑฐ๋, ๋ค๋ฅธ ๋ฐ์ค๊ฐ ๋์ด๋ ๋ ๊ฐ์ด ๋์ด๋๋ค(stretch). ๋ํ, ์ถ๊ฐ ๊ณต๊ฐ์ด flex-grow ๊ฐ์ ๋ฐ๋ผ ๋ถ๋ฐฐ๋๋ค. auto
์ผ ๋์๋ ๋ฌ๋ฆฌ flex-basis: 0;
์ผ๋ก ์ค์ ํ๋ฉด ๋ด์ฉ ์ฃผ์์ ์ถ๊ฐ ๊ณต๊ฐ์ด ๊ณ ๋ ค๋์ง ์๋๋ค.6.6. flex-basis : content;
flex-basis: content;
๋ ์ฝํ
์ธ ํฌ๊ธฐ์ ๋ง๊ฒ ์๋์ผ๋ก ํฌ๊ธฐ๊ฐ ์กฐ์ ๋๋ค. ๊ณ ์ ํฌ๊ธฐ ์กฐ์ ํค์๋๋ก๋ fill
, min-content
, max-content
, fit-content
๊ฐ ์๋ค.์ด ํค์๋๋ ์ ์ง์๋์ง ์๊ธฐ ๋๋ฌธ์ ํ
์คํธํ๊ธฐ ์ด๋ ต๋ค (2022๋
๊ธฐ์ค). ๋ฐ๋ผ์
min-content
, max-content
๋ฐ fit-content
์ ๊ธฐ๋ฅ์ ์์ ํ ํ์
ํ์ฌ ์ํ๋ ์๋๋๋ก ์ฌ์ฉํ๊ธฐ์ ์์ง ๋ฌด๋ฆฌ๊ฐ ์๋ค.6.7. flex-basis๋ณด๋ค๋ flex ์ถ์ฝ ์์ฑ์! (W3C)
CSS ํ์ค์ ๊ด๋ฆฌํ๋ W3C์ ๋ฐ๋ฅด๋ฉด, flex-basis ์์ฑ์ ์ง์ ์ฌ์ฉํ๊ธฐ๋ณด๋ค๋ flex ์ถ์ฝ ์์ฑ์ผ๋ก ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅํ๊ณ ์๋ค.
6.8. flex-basis ํธํ์ฑ
7. Flex-grow
7.1. flex-grow๋?
flex-grow
๋ ์์ ์์์ธ flex-item
์ด ์ฐจ์งํ๋ ๋น์จ์ ์กฐ์ ํ๋ ์์ฑ์ด๋ค. ์ปจํ
์ด๋ ํฌ๊ธฐ์ ๋ง์ถฐ ๋์ด๋๋ ๋น์จ์ด ์ฌ๋ฐฑ์ ์ฐจ์งํ๋ฉด์ ์ด ์์ฑ์ ๊ฐ์ง ๋ค๋ฅธ ์์๋ค๊ณผ ๋์ผํ๊ฒ ๋ถ๋ฐฐํ๋ค. ์ฝ๊ฒ ๋งํด์ flex-grow
์ ๊ฐ์ ์์ดํ
๋ค์ flex-basis
๋ฅผ ์ ์ธํ ์ฌ๋ฐฑ ๋ถ๋ถ์ flex-grow
์ ๋น์จ๋ก ๊ฐ๊ฐ ๋๋์ด ๊ฐ์ง๋ค.7.2. flex-grow ๊ธฐ๋ฅ : ํ์ฅ ๋๋ ๊ณ ์
.item { flex-shrink: 0; /* ๊ธฐ๋ณธ๊ฐ */ }
/* <number> values */ flex-grow: 1 | 0.5; /* Global values */ flex-grow: inherit | initial | unset;
flex-grow
์์ฑ์ ๊ธฐ๋ณธ๊ฐ์ด 0 ์ด๋ค. flex-grow:0
์ผ๋๋ flex item
์ ํ์ฅํ์ง ์๊ณ ์๋์ ํฌ๊ธฐ๋ฅผ ์ ์งํ๋ค. flex-grow:1
์ผ ๋๋ flex item
์ด ์ ์ฐํ ๋ฐ์ค์ ํํ๋ก ๋ฐ๋๋ฉฐ ๋น ๊ณต๊ฐ์ ์ฑ์ด๋ค. ๊ฐ๊ฐ์ ์์ดํ
๋ณ๋ก
flex-grow
๊ฐ์ ์ค ์๋ ์๋ค. flex-grow
์ ์ ํด์ค ๋น์จ๋งํผ ์ฌ๋ถ์ ์ปจํ
์ด๋ ๋๋น๋ฅผ ๋ถ๋ฐฐํ์ฌ ๊ฐ๋๋ค.7.3. flex-grow ์ฌ์ฉ ์ ์ฃผ์ํ ์
flex-grow
์์ฑ์ 0 ๋๋ ์์ ์ ์์ ๊ฐ์ผ๋ก ์ค์ ํด์ผ ํ๋ค. ์์์ ๊ฐ์ผ๋ก ์ค์ ํ์ ๊ฒฝ์ฐ, ๊ธฐ๋ณธ๊ฐ์ธ flex-grow:0
์ผ ๋์ ๊ฐ๋ค. ๋ํ flex-grow
์ ์ฆ๊ฐ๋๋น ๋น์จ์ width๋ก ์ธํด ์ํฅ์ ๋ฐ๋๋ค. ๋๋ฌธ์ flex-basis
๋ก flex์ ๊ฐ๋ณ ๋ฒ์์ ์
๋ ฅํ์ฌ ๊ธฐ๋ณธ๊ฐ์ ์ ํ๋ ๊ฒ์ด ์ข๋ค.7.4. flex ์ถ์ฝ ์์ฑ
flex: flex-grow | flex-shrink | flex-basis;
์ผ๋ฐ์ ์ผ๋ก๋ ๋ชจ๋ ๊ฐ์ด ์ค์ ๋์์์ ๋ณด์ฅํ๊ธฐ ์ํ์ฌย flex ์์ฑ์ ์ด์ฉํดย ์ถ์ฝํ์ผ๋ก ์ฌ์ฉํ๋ค. ์ถ์ฝ ์์ฑ์ ์์๋
flex-grow
, flex-shrink
, flex-basis
์์ผ๋ก ์ ์ฉ๋๋ฉฐ ๋์ด์ฐ๊ธฐ๋ก ๊ตฌ๋ถํ๋ค. Flex ์ถ์ฝ ์์ฑ์ ๊ธฐ๋ณธ๊ฐ์ flex: 0 1 auto; ์ด๋ค. flex-grow๋ฅผ ์ ์ธํ ๊ฐ๋ณ ์์ฑ์ ์๋ตํ ์ ์๋ค. flex : 1; ํ ๊ฒฝ์ฐ grow๋ 1๋ก ๋ณํ๊ณ shrink์ ๊ฐ์ 0์ผ๋ก basis์ ๊ฐ์ ๋ช
์์ ์ผ๋ก ์์ฑํ์ง ์์ผ๋ฉด 0์ผ๋ก ์
๋ ฅ์ด ๋๋ค.
7.5. flex-shrink๋ณด๋ค๋ flex ์ถ์ฝ ์์ฑ์! (W3C)
CSS ํ์ค์ ๊ด๋ฆฌํ๋ W3C์ ๋ฐ๋ฅด๋ฉด, flex-shrink์์ฑ์ ์ง์ ์ฌ์ฉํ๊ธฐ๋ณด๋ค๋
flex ์ถ์ฝ ์์ฑ์ผ๋ก ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅํ๊ณ ์๋ค.
7.6. flex-grow ํธํ์ฑ
์ง์๋ฒ์
8. Flex-shrink
8.1. Flex-shrink ๋?
flex-shrink
๋ ์์ ์์์ ์ฌ์ฉํ๋ ์์ฑ์ด๋ค. flex ์ปจํ
์ด๋ ์์์ ์์ ์์์ธ flex ์์ดํ
์์๋ฅผ ์๋์ผ๋ก ์ค์ฌ์ ์ ์ ํ ํฌ๊ธฐ๋ก ๋ฐฐ์นํด ์ ์ฐํ ๋ ์ด์์์ ๋ง๋ค ์ ์๋ค๋ ์ฅ์ ์ด ์๋ค. flex-basis
์์ฑ์ผ๋ก ์ง์ ๋ ์์ดํ
์ ๊ธฐ๋ณธ ํฌ๊ธฐ๋ฅผ ์ค์ ํ ์ซ์ ๊ฐ์ ๋น๋กํด ์์ถ์ํฌ ์ ์๋ค. flex-grow
์๋ ๋ฐ๋๋๋ ๊ฐ๋
์ด๋ค.8.2. Flex-shrink ๊ธฐ๋ฅ: ์ถ์ ๋๋ ๊ณ ์
.item { flex-shrink: 1; /* ๊ธฐ๋ณธ๊ฐ */ }
flex-shrink
์์ฑ์ ๊ธฐ๋ณธ๊ฐ์ 1์ด๋ค. ์ฆ, ์ ์ํ์ง ์์๋ ์๋์ผ๋ก ์ถ์๋๋ค. ์ซ์๊ฐ ํด์๋ก ์๋์ ์ผ๋ก ๋ ์์ ํฌ๊ธฐ๋ฅผ ๊ฐ๊ฒ ๋๋ค. ๊ฐ์ 0์ผ๋ก ์ ์ธํ ๊ฒฝ์ฐ ๋๋น ํน์ ๋์ด๋ฅผ ๊ณ ์ ํด์ ํญ์ ์ ์งํ ์ ์๋ค. ย
8.3. Flex-shrink ์ฌ์ฉ ์ ์ฃผ์ํ ์
flex-shrink
์์ฑ์ ๋ถ๋ชจ ์ปจํ
์ด๋์ flex-wrap: wrap;
์์ฑ์ ๋ถ์ฌํ ๊ฒฝ์ฐ ์ ์ฉ๋์ง ์๋๋ค. ๋ฐ๋ผ์ ์ ์ฉ์ ์ํด์๋ wrap
์ ์ ์ํ์ง ์๊ฑฐ๋, nowrap
์์ฑ์ด ๋ถ์ฌ๋์ด์ผ ํ๋ค.flex-basis: 250px ํต์ผ, 3๋ฒ์งธ ์์ดํ
๋ง flex-shrink: 2 ์ผ ๋ (์์3, 4)
ย
8.4. Flex ์ถ์ฝ ์์ฑ
flex: <flex-grow> <flex-shrink> <flex-basis>
flex-grow
, flex-shrink
, flex-basis
์์ฑ์ ๊ฐ์ ๋จ์ถํด์ ์ฌ์ฉํ ์ ์๋ ๊ฒ์ด flex
์ถ์ฝ ์์ฑ์ด๋ค. ์์๋ grow, shrink, basis ์์ผ๋ก ์ ์ฉ๋๋ค.flex-grow
๋ flex ์์ดํ ์ด ํฝ์ฐฝํ๋ ๋น์จ์ ์ค์ ํ๋ค. ๊ธฐ๋ณธ๊ฐ์ 0์ด๋ค.
flex-shrink
๋ flex ์์ดํ ์ด ์์ถํ๋ ๋น์จ์ ์ค์ ํ๋ค. ๊ธฐ๋ณธ๊ฐ์ 1์ด๋ค.
flex-basis
๋ flex ์์ดํ ์ด ํฝ์ฐฝํ๊ณ ์์ถํ๋ ๊ธฐ์ค ํฌ๊ธฐ๋ฅผ ์ค์ ํ๋ค. ๊ธฐ๋ณธ๊ฐ์ auto์ด๋ค.
8.5. Flex-shrink๋ณด๋ค๋ Flex ์ถ์ฝ ์์ฑ์! (W3C)
CSS ํ์ค์ ๊ด๋ฆฌํ๋ W3C์ ๋ฐ๋ฅด๋ฉด, flex-shrink์์ฑ์ ์ง์ ์ฌ์ฉํ๊ธฐ๋ณด๋ค๋ flex ์ถ์ฝ ์์ฑ์ผ๋ก ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅํ๊ณ ์๋ค.
8.6. Flex-shrink ํธํ์ฑ (caniuse)
9. ๊ทธ ๋ฐ์ Flex-item์ ์ฌ์ฉํ๋ ์์ฑ๋ค
๊ธฐํ flex-item์ ์ฌ์ฉํ๋ ์์ฑ์๋
align-self
, order
, ๊ทธ๋ฆฌ๊ณ z-index
๊ฐ ์๋ค. 9.1. align-self
align-self
๋ ๊ต์ฐจ ์ถ(cross-axis)์ ๊ธฐ์ค์ผ๋ก ๊ฐ๋ณ์์ดํ
์์์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ๊ฒฐ์ ํ๋ ์์ฑ์ด๋ค. Flex ์ปจํ
์ด๋์ ์ ์ฉํ์ฌ ๋ด๋ถ์ ์๋ ์ ์ฒด ์์ดํ
์ ์ ๋ ฌํ๋ align-items
์ ๋ฌ๋ฆฌ, align-self
๋ ์ธ์ ํ Flex ์์ดํ
์ ์ํฅ์ ์ฃผ์ง ์๊ณ , ๊ฐ๊ฐ์ Flex ์์ดํ
์์น๋ฅผ ์์ ๋กญ๊ฒ ๋ณ๊ฒฝํ ์ ์๋ค. ๋ฐ๋ผ์ ์ ์ฒด ์ค์ ์ธ align-items
๋ณด๋ค, ๊ฐ๋ณ ์์ดํ
์ ์ ์ฉ๋๋ align-self
์์ฑ์ด ์ฐ์ ํ๋ค๋ ํน์ง์ด ์๋ค. align-self์ ์์ฑ๊ฐ
align-self
์ ์์ฑ๊ฐ์, auto ๊ฐ์ ์ ์ธํ๋ฉด align-items
์ ์์ฑ๊ฐ๊ณผ ๊ฐ๋ค. - auto : ๊ธฐ๋ณธ๊ฐ์ผ๋ก, ํ๋ ์ค๋ฐ์ค ์ปจํ
์ด๋์
align-items
์์ฑ์ ์์๋ฐ๋๋ค. align-items์ ๊ธฐ๋ณธ ์์ฑ์ stretch์ด๊ธฐ ๋๋ฌธ์, align-items๊ฐ ์ง์ ๋์ด์์ง ์๋ ๊ฒฝ์ฐ stretch ์์ฑ์ ์์๋ฐ๋๋ค.
- stretch : ๊ต์ฐจ ์ถ์ ๊ธฐ์ค์ผ๋ก, ์ปจํ ์ด๋์ ๋์ด๋ฅผ ์ฑ์ฐ๊ธฐ ์ํด ํ๋ ์ค ์์ดํ ์ด ๋์ด๋๋ค.
- flex-start : ๊ต์ฐจ ์ถ์ ๊ธฐ์ค์ผ๋ก, ํ๋ ์ค ์์ดํ ์ด ์ปจํ ์ด๋์ ์์์ ์ ์ ๋ ฌ๋๋ค.
- flex-end : ๊ต์ฐจ ์ถ์ ๊ธฐ์ค์ผ๋ก, ํ๋ ์ค ์์ดํ ์ด ์ปจํ ์ด๋์ ๋์ ์ ์ ๋ ฌ๋๋ค.
- center : ๊ต์ฐจ ์ถ์ ๊ธฐ์ค์ผ๋ก, ํ๋ ์ค ์์ดํ ์ด ์ปจํ ์ด๋์ ์ค์์ ์ ๋ ฌ๋๋ค.
- baseline : ๊ต์ฐจ ์ถ์ ๊ธฐ์ค์ผ๋ก, ํ๋ ์ค ์์ดํ ์ด ์ปจํ ์ด๋์ ๋ฌธ์ ๊ธฐ์ค์ ์ ์ ๋ ฌ๋๋ค.
์๋๋ ์์ดํ
์ auto, stretch, flex-start, flex-end, center, baseline ์์ฑ๊ฐ์ ๋ถ์ฌํ ๋ชจ์ต์ด๋ค. ์ปจํ
์ด๋๊ฐ
flex-direction:row;
์ธ ๊ฒฝ์ฐ ๊ต์ฐจ ์ถ์ธ ์ธ๋ก์ถ์ ๊ธฐ์ค์ผ๋ก, ์์ดํ
๋ค์ด ์ปจํ
์ด๋๋ฅผ ์ฑ์ด๋ค. .container{ display: flex; flex-direction: row; } .item:nth-child(1){align-self: auto;} .item:nth-child(2){align-self: stretch;} .item:nth-child(3){align-self: flex-start;} .item:nth-child(4){align-self: flex-end;} .item:nth-child(5){align-self: center;} .item:nth-child(6){align-self: baseline;}
flex-direction:column;
์ผ ๋๋ ๊ต์ฐจ ์ถ์ธ ๊ฐ๋ก์ถ์ ๊ธฐ์ค์ผ๋ก, ์์ดํ
๋ค์ด ์ปจํ
์ด๋๋ฅผ ์ฑ์ด๋ค. .container{ display: flex; flex-direction: column; }
ย
align-self์ ํ์ฉ ์์
์๋๋ Flex ์ปจํ
์ด๋์ ์์ดํ
๋ค์ align-self ์์ฑ์ ์ฌ์ฉํ์ฌ ๊ฐ๋จํ๊ณ ์ฝ๊ฒ ์ ๋ ฌํ ๋ชจ์ต์ด๋ค. ์ปจํ
์ด๋์
flex-direction:column;
์ ๋ถ์ฌํ๊ณ , ์ฒซ ๋ฒ์งธ Flex ์์ดํ
์ align-self:flex-end;
๋ฅผ, ๋ค ๋ฒ์งธ Flex ์์ดํ
์ align-self:flex-start;
์ ์ฃผ์ด ๋ฐฐ์นํ์๋ค. ๊ฐ์ด ๋ถ์ฌ๋์ง ์์ ๋ ๋ฒ์งธ์ ์ธ ๋ฒ์งธ ์์ดํ
์์๋ align-self:auto;
๊ฐ ๋์ด, ์ปจํ
์ด๋์ align-items
์ ๊ธฐ๋ณธ๊ฐ์ธ stretch ์์ฑ์ ๋ถ์ฌ๋ฐ์ ๊ฒ์ ํ์ธํ ์ ์๋ค. .container{ display: flex; flex-direction: column; } .item:nth-child(1){align-self: flex-end;} .item:nth-child(4){align-self: flex-start;}
9.2. order
order
์์ฑ์ ์์ดํ
์์๋ค์ ์์๋ฅผ ๊ฒฐ์ ํ๋ ์์ฑ์ด๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก flex
๋ ์์ฑํ ์์๋๋ก ๋์ด๋์ง๋ง, order
์์ฑ์ ์ฌ์ฉํ์ฌ ์์ดํ
๋ค์ ์์๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ค. order์ ํน์ง
- ๊ธฐ๋ณธ๊ฐ์ 0์ด๋ฉฐ, ์์์ ์์๋ฅผ ์ฌ์ฉํ ์ ์๋ค. ๊ฐ์ด ์์์๋ก ์ฐ์ ์์๊ฐ ์ ์ฉ๋์ด
์์ โ 0 โ ์์
์์๋ก ํ์๋๋ค.
flex-direction
์์ฑ์ ๋ฐฉํฅ๊ฐ(row, row-reverse, column, column-reverse)์ ๊ธฐ์ค์ผ๋ก ๋ฎ์ ์ซ์๋ฅผ ๋จผ์ ๋ฐฐ์นํ๋ค.
- HTML ๊ตฌ์กฐ์ ์๊ด์์ด ์์๋ฅผ ์๊ฐ์ ์ผ๋ก ๋ณ๊ฒฝํ ์ ์์ง๋ง, HTML ์์ฒด์ ๊ตฌ์กฐ๋ฅผ ๋ฐ๊พธ๋ ๊ฒ์ ์๋๋ค. ๋ฐ๋ผ์ ์คํฌ๋ฆฐ๋ฆฌ๋๊ฐ ์ฝ์ ๋๋
order
๊ฐ์ด ์ ์ฉ๋์ง ์๊ณ HTML ๋งํฌ์ ์์๋๋ก ์ฝํ๋ค.
ย
์๋๋
flex-direction: row;
์ flex-direction: column;
์์ order
๊ฐ์ ์ ์ฉํ์ง ์์์ ๋์ ์ ์ฉํ์ ๋์ ๋ชจ์ต์ด๋ค. ย
flex-direction: row;
- order ๊ฐ์ ์ ์ฉํ์ง ์์ ๋ชจ์ต
ย
- order๊ฐ์ ์ ์ฉํ ๋ชจ์ต
.item:nth-child(1) {order: 2;} .item:nth-child(2) {order: 3;} .item:nth-child(3) {order: 1;}
ย
flex-direction: column;
- order ๊ฐ์ ์ ์ฉํ์ง ์์ ๋ชจ์ต
ย
- order๊ฐ์ ์ ์ฉํ ๋ชจ์ต
ย
order์ ์ฌ์ฉ ์์
- ๋ ์ง์ ์ ๋ชฉ, ๋ด์ฉ์ด ์๋ ์นด๋ ๋์์ธ์ ๋ง๋ ๋ค๊ณ ๊ฐ์ ํ์. ์๋์ ์ด๋ฏธ์ง์ฒ๋ผ ๋ ์ง๊ฐ ์ ๋ชฉ๋ณด๋ค ๋จผ์ ์์นํ๊ฒ ํ ๋, ๊ธฐ๋ณธ ์์๋ก ๋ฐฐ์นํ๋ค๋ฉด ์คํฌ๋ฆฐ ๋ฆฌ๋๋ ๋ ์ง, ์ ๋ชฉ, ๋ด์ฉ ์์ผ๋ก ์ฝ์ ๊ฒ์ด๋ค. ํ์ง๋ง ์ฌ์ฉ์๋ ๊ฐ์ฅ ์ค์ํ ์ ๋ชฉ์ ๋จผ์ ์ฝ์ ํ ๋ ์ง๋ฅผ ์ฝ๊ธฐ๋ฅผ ์ ํธํ๋ค. ์ด๋ด ๊ฒฝ์ฐ, ๋ ์ง์
order:-1
์ ์ฃผ์ด ์๊ฐ์ ์์๋ง ๋ฐ๊ฟ์ ์คํฌ๋ฆฐ ๋ฆฌ๋๊ฐ ์ฝ๋ ์์๋ฅผ ๋ณ๊ฒฝํ์ง ์๋๋ก ํ ์ ์๋ค.
ย
ย
- ์๋์ ๊ฐ์ ๊ฒฝ์ฐ์๋ order ์์ฑ์ ์ฌ์ฉํ ์ ์๋ค.
์ด๋ฏธ ๋ง๋ค์ด์ง ๋ชจ๋์ ์ฌ์ฉํ์ฌ ์น์ ๊ตฌ์ฑํ๋ค๋ฉด ์ด๊ธฐ์๋ ์๋์ ๊ฐ์ ๋ฐฐ์น๊ฐ ๋๋ค. ๋งํฌ์
์์๊ฐ header๋ถํฐ footer๊น์ง ์ฐจ๋ก๋๋ก ๋์ด์์ผ๋ฏ๋ก, ๊ฐ ์์์ ํฌ๊ธฐ๋ฅผ ์กฐ์ ํด์ฃผ์ด๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์์๋ ๋ฐ๋์ง ์๋๋ค.
ย
- order ์์ฑ์ ์ฃผ์ง ์์์ ๋
์์๋ค์ ํฌ๊ธฐ๋ฅผ ์กฐ์ ํด์ฃผ์์ง๋ง, ๋งํฌ์
์์๋๋ก ๋ฐฐ์น๋๊ธฐ ๋๋ฌธ์ order ์์ฑ์ ์ฃผ์ง ์๋๋ค๋ฉด ๊ธฐ๋ณธ์ ์ธ ์์๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ค.
ย
- order ์์ฑ์ ์ฃผ์์ ๋
ํ์ฌ main ๋ถ๋ถ์ ๊ฐ์ด๋ฐ๋ก ์ฎ๊ธฐ๋ ค๊ณ ํ๋ค. ๊ทธ๋ฌ๋ฏ๋ก aside-a, main, aside-b ์์์ ๊ฐ๊ฐ order๋ฅผ ์ฃผ๋ฉด ๋ฐฐ์น๊ฐ ๋์ง๋ง, ๊ธฐ๋ณธ์ ์ผ๋ก order ๊ฐ์ 1์ด๋ผ๋ ์ฃผ๊ฒ ๋๋ฉด, order ๊ฐ์ด ์๋ ์์ฑ์ด ๋ ์ฐ์ ์๋๊ธฐ ๋๋ฌธ์ ๋งํฌ์
์ ์๋์ ์๋ footer ๋ถ๋ถ์๋ order ๊ฐ์ ์ฃผ์ด์ผ ํ๋ค. ์ฆ ์ฐ๋ฆฌ๊ฐ ์ํ๋ ์์๋๋ก ๊ฐ ์์์ order๋ฅผ 1, 2, 3, 4๋ฅผ ์ฃผ๊ฒ ๋๋ฉด, ์ฐ๋ฆฌ๊ฐ ์ํ๋ ๋ ์ด์์์ ๋ง๋ค ์ ์๋ค.
.main { width: 60%; order: 2; } .aside { width: 20%; } .aside.aside-a { order: 1; } .aside.aside-b { order: 3; } .footer { order: 4; }
9.3. z-index
flex์์๋ z-index ์์ฑ์ ์ฌ์ฉํ ์ ์๋ค. ์ด๋ค ์์์ z-index์ ๊ฐ์ด 1์ด๋ผ๋ ์ฃผ์ด์ง๋ค๋ฉด ๋ง์น ๋ค๋ฅธ ์์๋ฅผ ๋ฎ์ด ์์ฐ๋ ๊ฒ๊ณผ ๊ฐ์ ๋ชจ์ต์ ํํํ ์ ์๋ค.
.main { width: calc(60% - 16px); order: 2; z-index: 1; transform: scale(1.5); opacity: 0.8; }
10. IE ์ง์์ ์ํ Flex
10.1. -ms- prefix ์ฌ์ฉ ์์
IE์์ ์ง์ํ์ง ์๋ Flex ์์ฑ
flex-flox
, justify-content: space-around
, align-self
, align-content
์ 4๊ฐ์ง ์์ฑ๋ค์ ํ์ฌ ์ง์ํ๊ณ ์์ง ์๋ค. ๋ flex-grow
, flex-shrink
, flex-basis
์ 3๊ฐ์ง ์์ฑ๋ค์ ๋จ์ถ ์์ฑ์ธ -ms-flex: 0 1 auto;
๋ฅผ ํตํด ์ง์ํ๊ณ ์๋ค. (IE10๋ฒ์ ์์๋ -ms-flex: 0 0 auto;
๋ฅผ ํตํด ์ง์ํ๊ณ ์๋ค.)Flex ์์ฑ IE ์ง์ ๋์ํ
์์ฑ | IE ์ง์ |
display: flex; | display: -ms-flexbox; |
flex-grow | -ms-flex |
flex-direction | -ms-flex-direction |
flex-wrap | -ms-flex-wrap |
order | -ms-flex-order |
justify-content | -ms-flex-pack |
align-items | -ms-flex-align |
10.2. IE์์์ Flex ์ด์
์ฃผ์ํด์ผ ํ Flex ์ด์
IE 10/11 ๋ฒ์ ์์ Flex๋ฅผ ์ฌ์ฉ ํ ๋ ์๊ฐ๋๋ก ์๋๋์ง ์๋ ์ด์๋ค๊ณผ ๋ง๋ฅ๋จ๋ฆด ์ ์๋๋ฐ, ๊ทธ ์ค ๋ช ๊ฐ์ง๋ฅผ ์๊ฐํ๊ฒ ๋ค.
- IE 10๊ณผ 11 ๋ฒ์ ์์ flex-basis ์ฌ์ฉ ์์
box-sizing: border-box;
๊ฐ ์ธ์๋์ง ์๋๋ค. IE 10/11์์๋ flex-basis๋ก flex item์ ํฌ๊ธฐ๋ฅผ ์ ํ ๋, flex item์ ํฌ๊ธฐ๋ฅผ ํญ์ item์ ์ฝํ ์ธ ํฌ๊ธฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ก๋๋ค.box-sizing: border-box;
์์ฑ์ ์ฃผ์ด๋ ๋ฐ๋์ง ์๋๋ค. ์ด๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ ์ค ํ๋๋ flex item์ ๊ฐ์ธ๋(wrapper) ์์๋ฅผ ์ถ๊ฐํด ์ฃผ๋ ๊ฒ์ด๋ค. ์ด ๋ ์์๋ border๋ padding๊ฐ์ด ์์ด์ผ ํ๋ค.
- IE 10/11์์
min-height
์์ฑ์ flex container์ ์ฌ์ฉ ์, ์์ ํ๊ทธ์ธ flex item์ ๋ถ๋ชจ ํ๊ทธ์ธ flex container์ ํฌ๊ธฐ๋ฅผ ์ธ์ํ์ง ๋ชปํ๋ค. ์๋ฅผ ๋ค์ด, flex item์ ์์ง ์ ๋ ฌํ๊ณ ์ ํ ๋, ๋ถ๋ชจ์ธ flex container์ ๋์ด๊ฐ ์ธ์๋์ด์ผ ํ๋๋ฐ, item๋ค์ด ๋์ด๋ฅผ ์ธ์ํ์ง ๋ชปํ๊ฒ ๋๋ค. ์ด๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ผ๋ก๋ flex container๋ฅผ ๊ฐ์ธ๋ ๋ ๋ค๋ฅธ flex container์์(wrapper)๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด๋ค. ์ด๋ flex container๋ฅผ ๊ฐ์ธ๋ ๋ถ๋ชจ ์์๋ column direction ์์ฑ์ผ๋ก ์ง์ ํด์ฃผ์ด์ผ ํ๋ค.
ย
flex ์ด์ ํ์ธ ์ฌ์ดํธ
์ด ์ธ์๋ IE 10/11 ๋ฒ์ ์์ flex ์ฌ์ฉ์๋ ์ฌ๋ฌ ์ด์๊ฐ ์๋ค. ๋ค์์ flex ์ด์๋ฅผ ํ์ธํ ์ ์๋ ์ฌ์ดํธ์ด๋ค.
11. ์ฑ๋ฐฐ ๋ ์ด์์ ๊ทธ๋ฆฌ๊ธฐ
11.1. Flex ์์ฑ์ ์ด์ฉํ์ฌ ๊ธฐ๋ณธ ์ฑ๋ฐฐ ๋ ์ด์์ ๊ตฌํํ๊ธฐ
์ต์ข
์ฝ๋
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>์ฑ๋ฐฐ๋ ์ด์์1</title> <link rel="stylesheet" as="style" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" /> <style> :root { --dark: #504975; --white: #ffffff; --background: #fbfbff; --primary: #7661e2; --light: #eceafe; } * { font-family: Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif; } body { height: 100%; padding: 10%; box-sizing: border-box; } .container { width: 70%; height: 300px; padding: 22px; margin: 0 auto; border: 1px solid var(--dark); border-radius: 20px; background: #fff; box-shadow: 0px 4px 12px 0px #51459F14; } .item { height: 40px; /* padding: 0px ; ์ฝํ ์ธ ์ ๋ฐ๋ผ ์กฐ์ ํด์ฃผ์ธ์ */ border: 1px solid var(--dark); border-radius: 20px; background-color: var(--primary); color: var(--white); box-shadow: 0px 4px 15px 0px #51459F14; text-align: center; vertical-align: middle; line-height: 2.5; word-break: keep-all; } .wrap{ display: flex; flex-flow: row wrap; gap: 0.5rem; margin: 0.5rem 0; } .main-content, .left-sidebar, .right-sidebar{ background-color: var(--light); color: var(--dark); padding: 80px 0; } .main-content{ flex-grow: 2; order: 2; } .left-sidebar{ flex-grow: 1; order: 1; } .right-sidebar{ flex-grow: 1; order: 3; } </style> </head> <body> <div class="container"> <div class="item header">Header</div> <div class="wrap"> <div class="item main-content">Main Content</div> <div class="item left-sidebar">Left Sidebar</div> <div class="item right-sidebar">Right Sidebar</div> </div> <div class="item footer">Footer</div> </div> </body> </html>
- ์ปจํ
์ด๋ ์์ ์์๋ค์ ๋ฃ์ผ๋ฉด ๋งํฌ์
์์์ ๋ฐ๋ผ ์๋์ ์ผ๋ก ์์์ ์๋๋ก ์์ด๊ฒ ๋๋ค. ์ฐ๋ฆฌ๋
content
,sidebar
์์๋ค์ ๋๋ํ ๋ฐฐ์นํ๋ ๊ฒ์ด ๋ชฉ์ ์ด๋ค.
<div class="container"> <div class="header">Header</div> <div class="main-content">Main Content</div> <div class="left-sidebar">Left Sidebar</div> <div class="right-sidebar">Right Sidebar</div> <div class="footer">Footer</div> </div>
- ๋๋ํ ๋ฐฐ์นํ๊ณ ์ถ์ ์์๋ค์
wrap
์ผ๋ก ๋ฌถ์ด์ค๋ค.wrap
๋ถ๋ถ์display: flex;
๋ฅผ ์ ์ธํด ์ค์ผ๋ก์จflex-direction
๋ฐฉํฅ์ด ์ด๊ธฐ๊ฐ์ธrow
๋ก ์ ๋ ฌ๋๋ค. ๋ํflex
์์ฑ์ผ๋ก์ธํด ์์ ์์๋ค์ด ์ฝํ ์ธ ๊ฐ ์ฐจ์งํ๋ ๋งํผ์ ๋๋น๋ฅผ ๊ฐ๋๋ค.
<div class="container"> <div class="header">Header</div> <div class="wrap"> <div class="main-content">Main Content</div> <div class="left-sidebar">Left Sidebar</div> <div class="right-sidebar">Right Sidebar</div> </div> <div class="footer">Footer</div> </div>
.wrap{ display: flex; }
- ์์ดํ
์์๋ ์๋์ฐ ์ฐฝ ํฌ๊ธฐ์ ๋ฐ๋ผ์ ์์์ง๊ธฐ๋ ํ๊ณ ์ปค์ง๊ธฐ๋ ํ๋ค. ์ด๋ ๋น์จ์ ์ค์ ํด ์ฃผ๊ธฐ ์ํด ๋จ์ ์ฌ๋ฐฑ์ ๋๋ ๊ฐ์ง ์ ์๋๋ก ์ซ์๋ฅผ ์ง์ ํด์ค๋ค.
Main Content
๊ฐ ๊ฐ์ฅ ํฐ ๋น์จ์ ์ฐจ์งํด์ผ ํ๋ฏ๋กflex-grow:2;
๋ฅผ ์ง์ ํด์ฃผ๊ณ ๋๋จธ์ง๋flex-grow:1;
๋ก ์ง์ ํ๋ค.
.main-content{ flex-grow: 2; } .left-sidebar{ flex-grow: 1; } .right-sidebar{ flex-grow: 1; }
- ๋งํฌ์
์์์ ๋ฐ๋ผ
Left Sidebar
,Main Content
,Right Sidebar
์์ผ๋ก ์์ด๊ฒ ๋๋๋ฐ,Main Content
๋ฅผ ๊ฐ์ด๋ฐ๋ก ์ค๊ฒ ๋ฐฐ์นํด์ผ ํ๋ฏ๋กorder
์์ฑ์ ๊ฐ๊ฐ ์ ํด์ฃผ์ด ๋ธ๋ผ์ฐ์ ์์ ํ์๋๋ ๋ชจ์ต์ ์ง์ ํ์ฌ ์์ฑํ๋ค.
.main-content { flex-grow: 2; order: 2; } .left-sidebar { flex-grow: 1; order: 1; } .right-sidebar { flex-grow: 1; order: 3; }
11.2. Flex ์์ฑ์ ์ด์ฉํ์ฌ ๋ณํ๋ ์ฑ๋ฐฐ ๋ ์ด์์ ๊ตฌํํ๊ธฐ
์ต์ข
์ฝ๋
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Flexbox ์ฑ๋ฐฐ๋ ์ด์์2</title> <link rel="stylesheet" as="style" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" /> <style> :root { --dark: #504975; --white: #ffffff; --background: #fbfbff; --primary: #7661e2; --light: #eceafe; } * { font-family: Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif; } body { height: 100%; padding: 10%; box-sizing: border-box; } .container { width: 70%; padding: 22px; margin: 0 auto; border: 1px solid var(--dark); border-radius: 20px; background: #fff; box-shadow: 0px 4px 12px 0px #51459F14; } .item { height: 40px; /* padding: 0px ; ์ฝํ ์ธ ์ ๋ฐ๋ผ ์กฐ์ ํด์ฃผ์ธ์ */ border: 1px solid var(--dark); border-radius: 20px; background-color: var(--primary); color: var(--white); box-shadow: 0px 4px 15px 0px #51459F14; text-align: center; vertical-align: middle; line-height: 2.5; word-break: keep-all; } .wrap{ display: flex; flex-flow: row wrap; gap: 0.5rem; margin: 0.5rem 0; } .content, .sidebar{ background-color: var(--light); color: var(--dark); } .content{ flex-grow: 1; order: 2; padding: 30px 0; } .sidebar{ flex-grow: 1; order: 1; padding: 55px 0; } .footer{ width: 66%; margin-left: auto; margin-top: -50px; } </style> </head> <body> <div class="container"> <div class="item header">Header</div> <div class="wrap"> <div class="item content">Content</div> <div class="item content">Content</div> <div class="item sidebar">Sidebar</div> </div> <div class="item footer">Footer</div> </div> </body> </html>
- ๊ธฐ๋ณธ html ์ฝ๋๋ฅผ ์์ฑํด๋ณธ๋ค. ํฐ
container
์์header
,content
,footer
์ธ๊ฐ์ง๋ก ๋๋ ์ํ์์ ์ ์์ ํ๋ค.
<div class="container"> <div class="header">Header</div> <div class="content">Content</div> <div class="footer">Footer</div> </div>
content
๋ฅผ ์ธ๋ถํํ์ฌ 2๊ฐ์content
์ 1๊ฐ์sidebar
๊ฐ ์๋ก์ด ์์๋ก ๋์ฌ ์ ์๊ฒ๋ ๋ถํ ํ๊ณ ์์์์๋ก ํ๋์wrap
์ผ๋ก ๋ฌถ์ด์ค๋ค. ์ฐ๋ฆฌ๋wrap
์์์flex
๋ฅผ ์ด์ฉํ์ฌ ์์ ๋กญ๊ฒ ๋ณํ๋ ๋ ์ด์์์ ๋ฐฐ์นํ๋ ๊ฒ์ด ๋ชฉ์ ์ด๋ค.
<div class="container"> <div class="header">Header</div> <div class="wrap"> <div class="content">Content</div> <div class="content">Content</div> <div class="sidebar">Sidebar</div> </div> <div class="footer">Footer</div> </div>
content
์sidebar
์์๋ค์ ์์ ๋ถ๋ชจ ์์์ธwrap
์display:flex
์์ฑ์ ๋ถ์ฌํ๊ณ ๊ฐ ์์ ๊ฐ ์ฌ๋ฐฑ๊ณผ ๊ฐ๊ฒฉ์ ๋ถ์ฌํ๋ค. flex์ ํ์ ์์๋ค์ ๊ฐ๊ฒฉ์ ์กฐ์ ํ ๋๋gap
์์ฑ์ ์ด์ฉํ๋ฉฐ ๋ถ๋ชจ ์์์ธwrap
์์ ์ ์ฌ๋ฐฑ์ ์กฐ์ ํ ๋๋margin
์ ์ด์ฉํ๋ค.
.wrap{ display: flex; flex-flow: row wrap; gap: 0.5rem; margin: 0.5rem 0; }
contents
์ ์คํ์ผ์ ์กฐ์ ํด๋ณธ๋ค.flex-glow
์์ฑ์ผ๋ก ์ฌ๋ฐฑ์ ๋์ผํ๊ฒ ์ฃผ๋๋ก ํ๋กํผํฐ ๊ฐ์ 1๋ก ํต์ผํด์ฃผ๊ณ , ๋งํฌ์ ์์ ์content
๊ฐ ๊ฐ์ฅ ๋จผ์ ๋์์ผ ํ์ง๋ง ๋์์ธ ์์ผ๋ก๋sidebar
๊ฐ ์์ผ๋ก ๋์ค๋๋ก ์ค์ ํด์ฃผ์ด์ผ ํจ์ผ๋กorder
๊ฐ์sidebar
๋ณด๋ค ๋์ ์์์ ์ซ์๋ก ํํํ๋ค. (ํจ๋ฉ ๊ฐ์ ์์์ ๋์ด๋ฅผ ์ค์ ํ๊ธฐ ์ํ์ฌ ์์์ ๊ฐ์ ์ง์ ํ์๋ค)sidebar
์ ํฌ๊ธฐ๋ฅผ ์กฐ์ ํด์ค๋ค.content
์ ๊ฐ์ ์ฌ๋ฐฑ์ ๊ฐ์ง๊ธฐ ์ํ์ฌflex-glow
๊ฐ์ 1๋ก ํต์ผํ์๊ณ ,content
๋ณด๋ค ๋ ์ด์์ ์ ์์ผ๋ก ๋ฐฐ์นํ๊ธฐ ์ํ์ฌorder
๊ฐ์content
์order
๊ฐ 2๋ณด๋ค ์์ 1๋ก ์์ ํด๋ณธ๋ค.content
์ ๋ง์ฐฌ๊ฐ์ง๋กcontent
๋ณด๋จ ๋์ ์์์ ๋์ด๊ฐ์ ์ค์ ํ๊ธฐ ์ํ์ฌ ํจ๋ฉ๊ฐ์ ์ฃผ์๋ค.footer
์ ์คํ์ผ๋ง ์ฐจ๋ก์ด๋ค.footer
๋ฅผcontent
์ ๋ฐ๋ก ์๋ซ๊ณต๊ฐ์ผ๋ก ์ด๋์ํค๊ธฐ ์ํด์ ์ ์ฒดcontent
๊ฐ์ ์ ๋์ ์ผ๋ก ์ ์ฉํ ์ ์๋๋กfooter
์width
๋ฅผ ํผ์ผํฐ์ง์ ๊ฐ์ผ๋ก ๋ฃ๋๋ค. ๊ทธ๋ฆฌ๊ณfooter
๋ ๋ธ๋ก ์์์ด๋ฏ๋กfooter
์ ํด๋น ์ค ์ ์ฒด๋ฅผ ์ฐจ์งํ๋margin
์ ์ผ์ชฝ๊ฐ์auto
๋ก ๋ถ์ฌํ์ฌfooter
์ ์ผ์ชฝ ์ฌ๋ฐฑ์ ์๋์ผ๋ก ๊ฐ์ ธ๊ฐ ์ ์๋๋ก ์์ฑํ๋ค.- ๋ง์ง๋ง ๋จ๊ณ์ด๋ค.
footer
์ฌ๋ฐฑ์ ์ฌ๋ฐฑ์ ๋ฐ๋๋ผ๋ ์๋ฏธ์ธnagative margin
์ ์ ์ฉํ์ฌfooter
์์๋ฅผ ์์ชฝ์ผ๋ก ๋์ด์ฌ๋ ค์ฃผ๋ฉดflex
์ ๋ณํ๋ ์ฑ๋ฐฐ๋ ์ด์์ ์์ฑ์ด ๋๋๋ค.
.content{ flex-grow: 1; order: 2; padding: 30px 0; }
.sidebar{ flex-grow: 1; order: 1; padding: 55px 0; }
.footer{ width: 66%; margin-left: auto; }
.footer{ width: 66%; margin-left: auto; margin-top: -50px; }
ย
ย