ํฐ์คํ ๋ฆฌ ๋ทฐ
Flex (Flexible Box)
์์์ ํฌ๊ธฐ๊ฐ ๋ถ๋ถ๋ช ํ๊ฑฐ๋ ๋์ ์ธ ๊ฒฝ์ฐ์๋ ๊ฐ ์์๋ฅผ ์ ๋ ฌํ ์ ์๋ ํจ์จ์ ์ธ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ ๋ ์ด์์ ๋ฐฉ์
์ํ/์์ง ์ ๋ ฌ์ ๊ด๋ จ๋ ์์ฑ
<div class="container">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
</div>
์์ ๊ฐ์ div item๋ค์ด ์์ ๋ ์ํ ์ ๋ ฌ์ ํ๋ ๋ฐฉ๋ฒ์๋ ์ฌ๋ฌ๊ฐ์ง๊ฐ ์๋ค.
1. display : inline-block ์ฌ์ฉํ๊ธฐ
2. display : block , float : left ์ฌ์ฉํ๊ธฐ
ํ์ง๋ง ๋ ๋ฐฉ๋ฒ ๋ชจ๋ ๋ณต์กํ ๋ ์ด์์์์๋ ๊ตฌํ์ด ์ด๋ ต๊ณ ํ๊ณ์ ์ด ๋ฐ์ํ๊ธฐ๋ ํ๋ค.
๋ ์ด์์์ ๊ฐ๊ฒฐํ๊ณ ์ฝ๊ฒ ๊ตฌํํ ์ ์๋๋ก CSS3์ ์ถ๊ฐ๋ Flex ๋ผ๋ ๋ ์ด์์ ๋ฐฉ์์ ์ฌ์ฉํด๋ณด์.
๊ทธ๋ฅ item์ ๊ฐ์ธ๋ container์ display : flex ๋ฅผ ์ ์ฉํด์ฃผ๋ฉด ์์ฃผ ์ฝ๊ฒ ์ํ ์ ๋ ฌ์ด ๊ฐ๋ฅํ๋ค.
Flex
- Container : Items์ ๊ฐ์ธ๋ ๋ถ๋ชจ ์์
- Items
Flex Container ์ ์์ฑ๋ค
- display
- flex-flow
- flex-direction
- flex-wrap
- justify-content
- align-content
- align-items
flex-flow (๋จ์ถ ์์ฑ)
- flex Items์ ์ฃผ ์ถ์ ์ค์ ํ๊ณ Items์ ์ฌ๋ฌ ์ค ๋ฌถ์ (์ค ๋ฐ๊ฟ)์ ์ค์ ํ๋ค.
- flex-direction ๊ณผ flex-wrap ์ ๋จ์ถํ ์์ฑ์ด๋ค.
flex-flow : [flex-direction] [flex-wrap];
flex-direction
Items์ ์ฃผ ์ถ์ ์ค์ ํ๋ค.
- row : Items๋ฅผ ์ํ์ถ์ผ๋ก ์ผ์ชฝ -> ์ค๋ฅธ์ชฝ ํ์ (๊ธฐ๋ณธ ๊ฐ)
- row-reverse : ์ํ์ถ์ผ๋ก ์ค๋ฅธ์ชฝ -> ์ผ์ชฝ ํ์
- column : Items๋ฅผ ์์ง์ถ์ผ๋ก ์->์๋ ํ์
- column-reverse : ์์ง์ถ์ผ๋ก ์๋->์ ํ์
- ์ฃผ ์ถ (main-axis) ๊ณผ ์ํ ์ถ (cross-axis)
- row : Items๋ฅผ ์ํ ์ถ์ผ๋ก ํ์ํ๊ธฐ ๋๋ฌธ์ ์ฃผ ์ถ์ ์ํ , ๊ต์ฐจ ์ถ์ ์์ง
- column : Items๋ฅผ ์์ง ์ถ์ผ๋ก ํ์ํ๊ธฐ ๋๋ฌธ์ ์ฃผ ์ถ์ ์์ง , ๊ต์ฐจ ์ถ์ ์ํ
flex-wrap
Items์ ์ฌ๋ฌ ์ค ๋ฌถ์์ ์ค์ ํ๋ค. (์ค ๋ฌถ์์ ํ ์ง ๋ง์ง ๊ฒฐ์ )
- nowrap : ๋ชจ๋ Items์ ํ์ค๋ก ํ์ (๊ธฐ๋ณธ ๊ฐ)
- wrap : Items์ ์ฌ๋ฌ ์ค๋ก ๋ฌถ์
- wrap-reverse : Items์ wrap์ ์ญ๋ฐฉํฅ์ผ๋ก ์ฌ๋ฌ ์ค๋ก ๋ฌถ์
ํฌ๊ธฐ๊ฐ ๊ฐ๋ณํ๋ ์ด์ ?
.container {
border: 4px solid;
display: flex;
}
.container .item {
width : 150px;
height : 100px;
background:tomato;
border: 4px dashed red;
border-radius : 10px;
}
์์ ๊ฐ์ด flex-wrap์ด ๊ธฐ๋ณธ๊ฐ์ธ nowrap ์ธ ์ํ์์ container์ ํฌ๊ธฐ๋ฅผ ์ค์๋ค ๋๋ ธ๋คํ๋ฉด Item๋ค์ ๋๋น๋ฅผ 150px๋ก ์ค์ ํ์์๋ ๋ถ๊ตฌํ๊ณ ๋๋น๊ฐ ์ค์ด๋ ๋ค.
์ด์ ๋ Item๋ค์ด container์ ํฌ๊ธฐ์ ๋ฐ๋ผ ๋ง์ถฐ์ง๋๋ฐ ์ด๋ ๊ฐ๊ฐ์ item๋ค์ด flex-basis๋ผ๋ ์์ฑ์์ auto๋ฅผ ๊ธฐ๋ณธ ๊ฐ์ผ๋ก ๊ฐ์ง๊ธฐ ๋๋ฌธ์ ๊ฐ๋ก/์ธ๋ก ๊ฐ์ด ๊ฐ๋ณํ๊ฒ ๋๋ ๊ฒ์ด๋ค.
justify-content
์ฃผ ์ถ์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ ํ๋ค.
- flex-start : Items์ ์์์ ์ผ๋ก ์ ๋ ฌ (์ผ์ชฝ ์ ๋ ฌ)
- flex-end : Items์ ๋์ ์ผ๋ก ์ ๋ ฌ (์ค๋ฅธ์ชฝ ์ ๋ ฌ)
- center : Items์ ๊ฐ์ด๋ฐ ์ ๋ ฌ
- space-between : ์์ Item์ ์์์ ์ ์ ๋ ฌํ๊ณ ๋ง์ง๋ง Item์ ๋์ ์ ์ ๋ ฌํ ๋ค, ๋๋จธ์ง Items๋ ์ฌ์ด์์ ๊ณ ๋ฅด๊ฒ ๋ถ๋ฐฐ๋์ด ์ ๋ ฌ
- space-around : ๊ฐ Items์ ๊ท ๋ฑํ ์ฌ๋ฐฑ์ ํฌํจํ์ฌ ์ ๋ ฌ
align-content
๊ต์ฐจ ์ถ์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ ํ๋ค.
* flex-wrap ์์ฑ์ ํตํด items๊ฐ ์ฌ๋ฌ ์ค์ด๊ณ ์ฌ๋ฐฑ์ด ์์ ๊ฒฝ์ฐ์๋ง ์ฌ์ฉ ๊ฐ๋ฅ!
- stretch : Container์ ๊ต์ฐจ ์ถ์ ์ฑ์ฐ๊ธฐ ์ํด Items ๋๋ฆผ
- flex-start : Items์ ์์์ ์ผ๋ก ์ ๋ ฌ
- flex-end : Items์ ๋์ ์ผ๋ก ์ ๋ ฌ
- center : Items์ ๊ฐ์ด๋ฐ ์ ๋ ฌ
- space-between : ์์ Item์ ์์์ ์ ์ ๋ ฌํ๊ณ ๋ง์ง๋ง Item์ ๋์ ์ ์ ๋ ฌํ ๋ค, ๋๋จธ์ง Items๋ ์ฌ์ด์์ ๊ณ ๋ฅด๊ฒ ๋ถ๋ฐฐ๋์ด ์ ๋ ฌ
- space-around : ๊ฐ Items์ ๊ท ๋ฑํ ์ฌ๋ฐฑ์ ํฌํจํ์ฌ ์ ๋ ฌ
align-items
๊ต์ฐจ ์ถ์์ Items์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ ํ๋ค. Items๊ฐ ํ ์ค์ผ ๊ฒฝ์ฐ ์ฌ์ฉํ๋ค.
- stretch : container์ ๊ต์ฐจ ์ถ์ ์ฑ์ฐ๊ธฐ ์ํด Items์ ๋๋ฆผ
- flex-start : Items์ ๊ฐ ์ค์ ์์์ ์ผ๋ก ์ ๋ ฌ
- flex-end : Items์ ๊ฐ ์ค์ ๋ ์ ์ผ๋ก ์ฐ๊ฒฐ
- center : Items์ ๊ฐ์ด๋ฐ ์ ๋ ฌ
- baseline : Items์ ๋ฌธ์ ๊ธฐ์ค์ ์ ์ ๋ ฌ
Flex Container ์ ์์ฑ๋ค
- order
- flex
- flex-grow
- flex-shrink
- flex-basis
- align-self
order
Flex Item์ ์์๋ฅผ ์ค์ ํ๋ค. ์ซ์๊ฐ ํด ์๋ก ์์๊ฐ ๋ฐ๋ฆฌ๊ณ ์์๋ฅผ ํ์ฉํ๋ค.
.item3 {
order: 1;
}
.item5 {
order: 7;
}
.item6 {
order: -1;
}
flex (๋จ์ถ ์์ฑ)
- Item์ ๋๋น๋ฅผ ์ค์ ํ๋ ๋จ์ถ์์ฑ์ด๋ค.
- Item์ ์ฆ๊ฐ ๋๋น ๋น์จ / ๊ฐ์ ๋๋น ๋น์จ / ๊ธฐ๋ณธ ๋๋น๋ฅผ ์ค์ ํ๋ค.
- flex ๋ผ๋ ๋จ์ถ ์์ฑ์์ flex-basis๋ฅผ ์๋ตํ ๊ฒฝ์ฐ, flex-basis์ ๊ธฐ๋ณธ ๊ฐ์ auto๊ฐ ์๋๋ผ 0์ด๋ค.
flex : [flex-grow] [flex-shrink] [flex-basis]
flex-grow
Item์ ์ฆ๊ฐ ๋๋น ๋น์จ์ ์ค์ ํ๋ค. ์ซ์๊ฐ ํด ์๋ก ๋ง์ ๋๋น๋ฅผ ๊ฐ์ง๋ค.
item ์์ฒด์ ๋๋น๋ฅผ 100px๋ก ์ค์ ํด๋์ด์ 1๊ณผ 2์ ๋๋น๊ฐ ์ ํํ 2๋ฐฐ ์ฐจ์ด๊ฐ ๋์ง๋ ์๋๋ค.
item์ width๋ฅผ ์ง์ฐ๊ณ 3์๋ง 100px ๋๋น๋ฅผ ์ค์ ํด์ฃผ๋ฉด ๋ค์๊ณผ ๊ฐ์ด 1๊ณผ 2์ ๋๋น ๋น์จ์ด 1:2๋ก ์ ํํด์ง๋ค.
flex-grow ๊ฐ ์ ์ฉํ๊ฒ ์ฌ์ฉ๋ ์์ )
item2๋ width : 100px๋ก ๊ณ ์ ๋์ด์๊ณ item1์ flex-grow : 1 ๋ก ์ค์ ๋์ด์๋ค.
1๋ฒ ๋ถ๋ถ์ ๊ฐ๋ก ๋๋น๋ง ๊ฐ๋ณ์ ์ผ๋ก ๋ณํ๊ณ 2๋ฒ์ ๋ณํ์ง ์๊ธฐ ๋๋ฌธ์ ์ด์ ๊ด๋ จ๋ ์์ ๋ฅผ ๋ง๋ค ๋ flex-grow๊ฐ ์ ์ฉํ๊ฒ ์ฌ์ฉ๋ ์ ์๋ค.
<div class="container">
<div class="item item1">1</div>
<div class="item item2">2</div>
</div>
.container {
border: 4px solid;
display: flex;
}
.container .item {
height : 100px;
background:tomato;
border: 4px dashed red;
border-radius : 10px;
font-size:30px;
display:flex;
justify-content:center;
align-items:center;
}
.item1 {
flex-grow:1;
}
.item2 {
width:100px;
}
flex-shrink
Item์ด ๊ฐ์ํ๋ ๋๋น์ ๋น์จ์ ์ค์ ํ๋ค. ์ซ์๊ฐ ํฌ๋ฉด ๋ ๋ง์ ๋๋น๊ฐ ๊ฐ์ํ๋ค.
Item์ด ๊ฐ๋ณ ๋๋น๊ฐ ์๋๊ฑฐ๋, ๊ฐ์ด 0์ผ ๊ฒฝ์ฐ ํจ๊ณผ๊ฐ ์๋ค.
flex-shrink๋ ์์์ ๋๋น์ ์ํฅ์ ๋ฐ์์ ๊ณ์ฐ์ด ๊น๋ค๋กญ๋ค.
* ์์์ ๋๋น : width, height, flex-basis ๋ฑ ๋๋น๊ฐ ์ง์ ๋ ๊ฒฝ์ฐ
์ผ์ชฝ ์์ ์์ container์ ๋๋น๊ฐ ์ค์ด๋ค์ด์ Item์ ๋๋น์ ์ํฅ์ ์ฃผ๊ธฐ ์์ํ ์์ ๋ถํฐ ์ค์ ์ค์ด๋ ๊ฑฐ๋ฆฌ๊ฐ 90px์ผ ๋,
์์ ๋๋น๊ฐ 200px๋ก ๊ฐ์ Item์ด 2๊ฐ์ด๊ณ ์ง์ ๋ ๊ฐ์ ๋๋น (flex-shrink)๊ฐ ๊ฐ๊ฐ 2์ 1์ด๋ผ๋ฉด, ๊ฐ์ ๋๋น๋ 2:1์ด๋ค.
์ฒซ๋ฒ์งธ Item์ 90px * 2/3 = 60px ๋งํผ ๊ฐ์ํ๊ณ , ๋๋ฒ์งธ Item์ 90px * 1/3 = 30px ๋งํผ ๊ฐ์ํ๋ค.
flex-basis
Item์ ๊ธฐ๋ณธ ๋๋น๋ฅผ ์ค์ ํ๋ค. ๊ฐ์ด auto์ผ ๊ฒฝ์ฐ width, height ๋ฑ์ ์์ฑ์ผ๋ก Item์ ๋๋น๋ฅผ ์ค์ ํ ์ ์๋ค.
align-self
๊ต์ฐจ ์ถ์์ ๊ฐ๋ณ Item์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ ํ๋ค.
align-items ์ ๊ฒฝ์ฐ๋ container ๋ด์ ๋ชจ๋ items์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ์ค์ ํ๋ค.
์ด๋, ๊ฐ๋ณ item์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ๋ณ๊ฒฝํ๊ณ ์ถ์ ๊ฒฝ์ฐ์๋ ํด๋น item์์ align-self ์์ฑ์ ์ฌ์ฉํ๋ฉด ๋๋ค.
container์ align-items๋ฅผ flex-end๋ก ์ค์ ํ๊ณ ๋ช๊ฐ์ item์ ๋ํด์๋ง ๊ต์ฐจ์ถ์์ ์ ๋ ฌ ๋ฐฉ๋ฒ์ ๋ฐ๊พธ์ด๋ณด์.
- 2๋ฒ : align-self : center;
- 4๋ฒ : align-self : flex-start;
- 7๋ฒ : align-self : stretch; height : auto;
'Front-end ๐ฅ๐ค > CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
- Total
- Today
- Yesterday
- ์กธ์ ์ํ์ค๋น
- ์ ๋ณด์ฒ๋ฆฌ๊ธฐ์ฌ ์ค๊ธฐ
- ํ์ฅ์ค์ต
- DAPP
- ๋ธ๋ก์ฒด์ธ
- ์ค๋งํธ์ปจํธ๋ํธ
- ๊ฐค๋ฌ๋ฆฌ๋์ฐ๊ธฐ
- MySQL
- ์กธ์ ์ํ
- ๋ ธ๋ง๋์ฝ๋
- JavaScript
- ์ ์ฒ๊ธฐ ์ค๊ธฐ
- ํํ์ด์ง ๋ง๋ค๊ธฐ
- php๊ฒ์ํ๋ง๋ค๊ธฐ
- ๋ฐฑ์ค
- php
- set ๊ฐ์ฒด
- css grid
- ์ด๋๋ฆฌ์
- ํ์ฅ์ค์ต ๊ธฐ๋ก
- ๋ฆฌ์กํธ
- C์ธ์ด
- ํ๋ก๊ทธ๋๋จธ์ค
- indexOf()
- ์ ์ฒ๊ธฐ ์ค๊ธฐ ์ ๋ฆฌ
- php ๋ฌ๋ ฅ๋ง๋ค๊ธฐ ์์ฉ
- HTML
- CSS
- ์ ๋ณด์ฒ๋ฆฌ๊ธฐ์ฌ
- ์ ๋ณด์ฒ๋ฆฌ๊ธฐ์ฌ ์ค๊ธฐ ์ ๋ฆฌ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |