flex๋ 1์ฐจ์์ผ๋ก ์ํ, ์์ง ์์ญ ์ค ํ๋์ ๋ฐฉํฅ์ผ๋ก๋ง ๋ ์ด์์์ ๋๋ ์ ์์ต๋๋ค.
display : flex
- ์ ๋ ฌ ํ๊ณ ์ ํ๋ ์์๋ฅผ ๊ฐ์ธ๋ ๋ถ๋ชจ์๊ฒ
display : flex
๋ฅผ ์ ์ธ ํฉ๋๋ค. - flex ์์ดํ
๋ค์ ๊ฐ๋ก ๋ฐฉํฅ์ผ๋ก ๋ฐฐ์น๋๊ณ , ์์ ์ด ๊ฐ์ง ๋ด์ฉ๋ฌผ์
width
๋งํผ๋ง ์ฐจ์ง ํฉ๋๋ค. - ์ ์ธ ์, ๋ณด์ด์ง ์๋ ๋ ๊ฐ์ ์ถ(Axis)์ด ์๊น๋๋ค.
.flexBox{
display: flex;
}
<div class="flexBox">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
๋ฉ์ธ์ถ(Main Axis), ์์ง์ถ ๋๋ ๊ต์ฐจ์ถ(Cross Axis)
- Main axis : flex-direction ๋ฐฉํฅ์ ๋ฐ๋ผ
- Cross axis : main๊ณผ ์์ง์ ์ด๋ฃจ๋ ๋ฐฉํฅ
flex-direction
์์๋ค์ด ๋ฐฐ์น๋๋ ์ถ์ ๋ฐฉํฅ์ ๊ฒฐ์ ํ๋ ์์ฑ
.flexBox{
display: flex;
flex-direction: row;
/* flex-direction: column; */
/* flex-direction: row-reverse; */
/* flex-direction: column-reverse; */
}
- row๊ฐ ๊ธฐ๋ณธ ์์ฑ ๊ฐ ์ ๋๋ค.
flex-direction : row
(์ผ->์ค) --> ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ๊ฐ๋ main axis ๊ฐ ๋ง๋ค์ด์ง๋๋ค. ๊ทธ๋ฆฌ๊ณ , ๊ทธ์ ์ ํํ๊ฒ ์์ง์ ์ด๋ฃจ๋ cross axis๊ฐ ๋์ต๋๋ค.(์->์๋)flex-direction : column
(์->์๋) --> ์์์๋ถํฐ ์๋๋ก ํ๋ฅด๋ main axis ๊ฐ ๋ง๋ค์ด์ง๋๋ค.
๊ทธ๋ฆฌ๊ณ , ๊ทธ์ ์ ํํ๊ฒ ์์ง์ ์ด๋ฃจ๋ cross axis ๊ฐ ๋์ต๋๋ค.(์ผ->์ค)- ๊ทธ์ธ
row-reverse
์column-reverse
๋ ๋ง์ฐฌ๊ฐ์ง ์ ๋๋ค. (reverse ๋ ๋ฐ๋๋ก ๋ค์ง์ด์)
- ์ด๋ฏธ์ง ์์๋
row
,column
,row-reverse
,column-reverse
์์ ์ ๋๋ค. row-reverse
๋ ์ด๋ฏธ์ง ์์ผ๋ก๋ ์์๋ง ์ญ์์ผ๋ก ๋ณด์ฌ์ง์ง๋ง ์ค์ ๋ก๋ ์์์ ์์น ๋ํ ์ผ์ชฝ๊ธฐ์ค ๋งจ ์ค๋ฅธ์ชฝ์ผ๋ก ๋ฌ๋ผ ๋ถ์ต๋๋ค.
justify-content
- justify-content : ๋ฉ์ธ์ถ ๋ฐฉํฅ์ผ๋ก ์์์ ์ ๋ ฌํ๋ ์์ฑ
.flexBox {
justify-content: flex-start;
/* justify-content: flex-end; */
/* justify-content: center; */
/* justify-content: space-between; */
/* justify-content: space-around; */
/* justify-content: space-evenly; */
}
flex-start (๊ธฐ๋ณธ๊ฐ)
: ๋ถ๋ชจ์ ์์๋ค์ ์์์ ์ผ๋ก ์ ๋ ฌํฉ๋๋ค.- flex-direction์ด row(๊ฐ๋ก ๋ฐฐ์น)์ผ ๋๋ ์ผ์ชฝ, column(์ธ๋ก ๋ฐฐ์น)์ผ ๋๋ ์.
flex-end
: ๋ถ๋ชจ์ ์์๋ค์ ๋ ์ ์ผ๋ก ์ ๋ ฌํฉ๋๋ค.- flex-direction์ด row(๊ฐ๋ก ๋ฐฐ์น)์ผ ๋๋ ์ค๋ฅธ์ชฝ, column(์ธ๋ก ๋ฐฐ์น)์ผ ๋๋ ์๋.
center
: ๋ถ๋ชจ์ ์์๋ค์ ๊ฐ์ด๋ฐ๋ก ์ ๋ ฌํฉ๋๋ค.space-between
: ๋ถ๋ชจ์ ์์๋ค ์ฌ์ด(between) ์ ๊ท ์ผํ ๊ฐ๊ฒฉ์ ๋ง๋ค์ด ์ค๋๋ค.space-around
: ๊ฐ์ด๋ฐ ์์ ๊ธฐ์ค ์ ์์ผ๋ก ๊ท ์ผํ ๊ฐ๊ฒฉ์ ๋ง๋ค์ด ์ค๋๋ค.space-evenly
: ๋ถ๋ชจ์ ์์๋ค ์ฌ์ด์ ์ ๋์ ๊ท ์ผํ ๊ฐ๊ฒฉ์ ๋ง๋ค์ด ์ค๋๋ค.
align-items
- align-items : ์์ง์ถ ๋ฐฉํฅ์ผ๋ก ์์์ ์ ๋ ฌํ๋ ์์ฑ (ํ๋์ flex๋ผ์ธ์ ํ๋ฅด๋ cross axis์ ๊ธฐ์ค)
.flexBox {
align-items: stretch;
/* align-items: flex-start; */
/* align-items: flex-end; */
/* align-items: center; */
/* align-items: baseline; */
}
- ๋ช ๊ฐ์ง ์์ฑ์ ๋นผ๊ณ ๋, justify-content ์์ ์ค๋ช ํ ์์ฑ๊ณผ ๋น์ทํ๊ธฐ ๋๋ฌธ์ ๊ทธ๋ฆผ์ผ๋ก ๋ณด๋ ๊ฒ์ด ์ดํดํ๊ธฐ ์ข์ต๋๋ค.
baseline
: ์์๋ค์ ํ ์คํธ ๋ฒ ์ด์ค๋ผ์ธ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํฉ๋๋ค.
์ ๋ฐ์ ์ผ๋ก
- flex ๊ฐ ๋ฌด์์ธ์ง, ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง ์ ๋ฆฌ ํ์์ต๋๋ค.
- ์์ ์์ฑ๋ง ์ฌ์ฉํด๋ ์ด๋์ ๋ ์์ดํ ๋ค์ ๋ํ ๋ฐฐ์น๋ ๊ฐ๋ฅํ๋ค๊ณ ์๊ฐ ํฉ๋๋ค.
- ๋๋จธ์ง ์์ธํ ์์ฑ๋ค์ ์ ๊ธฐ์ ๋ธ๋ก๊ทธ ์ ์๋์ ์ฐธ๊ณ ๋งํฌ๋ค์ ํ์ฉ ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
์ฐธ๊ณ
'๐ Front-End > CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
z-index (0) | 2022.10.20 |
---|---|
em & rem (0) | 2022.10.20 |
Grid (0) | 2022.10.20 |
position ์์ฑ (0) | 2022.10.19 |
display ์์ฑ (0) | 2022.10.19 |