์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- ๊ธฐํ
- ๋์ ๋์
- 23๋ ๋ง์ง๋ง
- UI
- uiux ๋์์ธ
- ์น/์ฑ ํ์ด์ง ์ ์
- ํฌ๋ชฝ
- UIUX๋์์ธ
- ์ด์ฌ
- Git ์ฐ๋
- ์๊ธฐ๊ด๋ฆฌ
- ์ฑ ๋์์ธ
- ์น ๋์์ธ
- ์ฌํด ๊ณํ
- ์ฑ๋์์ธ
- kmong
- ํ๋ก์ ํธ
- Flex
- UI/UX๋์์ธ
- ๊ฐ์ธ์ ์ธ
- ํฌํธํด๋ฆฌ์ค
- ์ทจ์ ์ค๋น
- Git
- CSS
- ๊ธฐํ์ฐ์ต
- ๊ธฐํ์ ๋ฆฌ
- ์นํ์ด์ง ๋์์ธ
- ์ ์ ์์
- ๊ณต๋ถ
- UX
- Today
- Total
Dall's Green๐ฟ
[CSS] CSS Flex ์์ฑ ์ ๋ฆฌ ๋ณธ๋ฌธ
์ผ๋ฐ์ ์ผ๋ก ์นํ์ด์ง์ ๋ ์ด์์์ css์ display, float, position ๋ฑ๊ณผ ๊ฐ์ ์์ฑ์ ์ฌ์ฉํด ๊ตฌํํ๋ค. ์ด๋ฌํ ์์ฑ์ ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ ์ด์์์ ํํํ๋ ๊ฒ์ ๊ต์ฅํ ๋ณต์กํด์ง๋ค.
์ด๋ฌํ ๋ณต์กํ ๋ ์ด์์์ ๊ฐ๋จํ๊ฒ ๊ตฌํํ ์ ์๊ฒ ๋์จ ๊ฒ์ด css3์ ์ถ๊ฐ๋ flexbox์ด๋ค. flexbox๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ์์์ ํฌ๊ธฐ์ ์์๋ฅผ ์ ์ฐํ๊ฒ ๋ฐฐ์นํ ์ ์๋ค.
# flex (flexbox)
flexbox๋ viewport๋ ์์์ ํฌ๊ธฐ๊ฐ ๋ถ๋ช ํํ๊ฑฐ๋ ๋์ ์ผ๋ก ๋ณํ ๋์๋ ํจ์จ์ ์ผ๋ก ์์๋ฅผ ๋ฐฐ์น, ์ ๋ ฌ, ๋ถ์ฐ์ํฌ ์ ์๋ค.
์ด๋ฌํ flexbox๋ ๋ณต์์ ์์ ์์์ธ flex item๊ณผ ๊ทธ ์์ ๋ถ๋ชจ ์์์ธ flex container๋ก ๊ตฌ์ฑ๋๋ค.
.flex_container {
display: flex;
}
display: flex ์์ฑ์ด ์ ์ฉ๋ ์์๋ flex container๊ฐ ๋๊ณ , flex contatiner์ ์์ ์์๋ ์๋์ ์ผ๋ก flex item์ด ๋๋ค.
์ด๋ฌํ flex item๋ ์ฃผ์ถ(main axis)์ ๋ฐ๋ผ ์ ๋ ฌ๋๋ค. ์ฃผ์ถ์ ๋ฐฉํฅ์ flex container์ flex-direction ์์ฑ์ผ๋ก ๊ฒฐ์ ํ๋๋ฐ, ๊ธฐ๋ณธ์ ์ผ๋ก๋ row ์์ฑ์ผ๋ก ์ง์ ์ด ๋์ด ์๋ค.
# ๋ถ๋ชจ ์์์ ์์ ์์ ์์ฑ ๊ตฌ๋ถ
flexbox์ ์ ์ฒด์ ์ธ ์ ๋ ฌ๊ณผ ํ๋ฆ ์์ฑ์ ๋ถ๋ชจ์ธ flex container์ ์ ์ํ๊ณ , ํฌ๊ธฐ๋ ์์์ ๊ด๋ จ๋ ์์ฑ์ ์์ ์์์ ํด๋นํ๋ flex-item์ ์ ์ํ๋ค.
์ด๊ฒ์ ๋ถ๋ฆฌํด์ ์ ์ฉํ๋ ๊ฒ์ด ๊ฐ์ฅ ์ค์ํ๋ค!
- flex container ์์ฑ: flex-direction, flex-wrap, justify-content, align-items, align-content
- flex item ์์ฑ: flex, flex-grow, flex-shrink, flex-basis, order
์ด๋ฌํ flexbox๋ internet explorer 10 ์ด์์ด ์ง์ํ๋ค. ์ง์์ ํ์ง ์๋ ๋ธ๋ผ์ฐ์ ๋ ์๋๋ฐ, ๋์ฒด์ ์ผ๋ก ๋ชจ๋ฐ์ผ ๋ธ๋ผ์ฐ์ ๋ flexbox๋ฅผ ์ง์ํ๋ค.
(์์ธํ ๊ฒ์ ๋ฐ์..)
# ์ง์ ์์ฑ (ํ์!)
- flex-direction: ๋ด๋ถ ์์๋ค์ ์ ๋ ฌ ๋ฐฉํฅ
.flex_container {
display: flex;
flex-direction: row; /* ๊ฐ๋ก๋ฐฉํฅ ์ ๋ ฌ (default)
default๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ, ์๋ต์ด ๊ฐ๋ฅํ๋ค. */
column; /* ์ธ๋ก๋ฐฉํฅ ์ ๋ ฌ */
row-reverse; /* ๊ฐ๋ก๋ฐฉํฅ์ ๋ฐ๋์์๋ถํฐ ์ ๋ ฌ */
column-reverse; /* ์ธ๋ก๋ฐฉํฅ์ ๋ฐ๋์์๋ถํฐ ์ ๋ ฌ */
}
# ๋ถ๋ชจ ์์ 4๊ฐ์ง
- flex-wrap : ์ค ๋ฐ๊ฟ ์ค์ , ์์ ์์๋ค์ ์๊ฐ ๋ง์์ ธ์ ๊ฐ์๊ฐ ๊ฝ ์ฐผ์ ๋ ์๋ ์ค๋ฐ๊ฟ์ ํด์ค๋ค.
.flex_container {
display: flex;
flex-wrap: nowrap /* ํ์ค ์ ๋ ฌ, default */
wrap /* ์ฌ๋ฌ์ค ๊ฑธ์ณ ์ ๋ ฌ */
wrap-reverse /* ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ์ฌ๋ฌ์ค ๊ฑธ์ณ ์ ๋ ฌ */
- justify-content: ๊ฐ๋ก์ ์ ์ ๋ ฌ
.flex_container {
display: flex;
justify-content: flex-start /* ์ผ์ชฝ ์ ๋ ฌ */
flex-end /* ์ค๋ฅธ์ชฝ ์ ๋ ฌ */
center /* ๊ฐ์ด๋ฐ ์ ๋ ฌ */
space-between /* ํ๋ฉด์ ๋ฑ๋ง๊ฒ ์ ๋ ฌ */
space-around /* ์๋ ๊ณต๊ฐ์ ์ผ์ ํ๊ฒ ๋์ด ์ ๋ ฌ */
space-evenly /* ์๋๊ณผ ๊ฐ์ด๋ฐ ๊ณต๊ฐ์ด ๋ชจ๋ ์ผ์ ํ๊ฒ ๋์ด ์ ๋ ฌ */
- align-items: ์ธ๋ก์ ์ ์ ๋ ฌ
.flex_container {
display: flex;
align-items: flex-start /* ์๋ก ์ ๋ ฌ */
flex-end /* ์๋๋ก ์ ๋ ฌ */
center /* ๊ฐ์ด๋ฐ ์ ๋ ฌ */
baseline /* ๋ฐ๋ฉด ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ */
stretch /* ์ ํํ ๋์ด๊ฐ์ ์ฃผ๋ฉด ๋ณํ์ง ์์ผ๋
์ต์๋์ด๋ฅผ ์ฃผ๋ฉด container ์์ญ๊น์ง ์ ๋ ฌ */
- align-content: (์ธ๋ก์ ์ ์ ๋ ฌ์์ ์ฌ๋ถ์ ๊ณต๊ฐ์ด ์๋ค๋ฉด) ์ปจํ ์ด๋ ์ฌ์ด ๊ฐ๊ฒฉ์กฐ์
.flex_container {
display: flex;
align-content: flex-start /* ์๋ก ์ ๋ ฌ */
flex-end /* ์๋๋ก ์ ๋ ฌ */
center /* ๊ฐ์ด๋ฐ ์ ๋ ฌ */
space-between /* ํ๋ฉด์ ์ผ์ ํ๊ฒ ์ ๋ ฌ */
space-around /* ๋ผ์ธ์ฌ์ด์ ๋์ผํ ๊ฐ๊ฒฉ์ผ๋ก ๋์ด ์ ๋ ฌ */
strech /* ์ค์ด ๋์ด๋ ๋๋จธ์ง ๊ณต๊ฐ์ ์ฐจ์ง, default */
# ์์์์ 5๊ฐ์ง
- flex: flex-grow, flex-shrink, flex-basis์ ์ถ์ฝํ ์์ฑ
์๋ ๋ด๊ฐ ๊ฐ์ง ๋ณธ์ฐ์ ํฌ๊ธฐ๋ฅผ 0์ผ๋ก ์ด๊ธฐํ ์ํจ๋ค. ๊ทธ๋์ ์ ์ฒด๊ฐ 1์ ๋น์จ ๊ท ๋ฑํ ๋น์จ๋ก ๋๋ ๊ฐ์ง ์ ์๋ค!
.flex_item {
display: flex;
flex: 1; /* flex-grow: 1; flex-shrink: 1; flex-basis: 0%; */
1 1 auto; /* flex-grow: 1; flex-shrink: 1; flex-basis: auto; */
1 500px; /* flex-grow: 1; flex-shrink: 1; flex-basis: 500px; */
}
- flex-grow: (0๋ณด๋ค ํฐ ๊ฐ์ด ๋ค์ด๊ฐ๋ฉด) ์ ์ฐํ ๋ฐ์ค๋ก ๋ณํ๊ณ ์๋์ ํฌ๊ธฐ๋ณด๋ค ์ปค์ง๋ฉฐ ๋น ๊ณต๊ฐ์ ๋ฉ์์ค๋ค.
.flex_item {
display: flex;
flex-grow: 1;
/* flex-grow: 0; , default */
}
- flex-shrink: (0 ๋ณด๋ค ํฐ ๊ฐ์ด ๋ค์ด๊ฐ๋ฉด) ์ ์ฐํ ๋ฐ์ค๋ก ๋ณํ๊ณ flex-basis๋ณด๋ค ์ค์ด๋ ๋ค.
.flex_item {
display: flex;
flex-shrink: 1;
/* flex-grow: 0; , default */
}
- flex-basis: Flex ์์ดํ ์ ๊ธฐ๋ณธ ํฌ๊ธฐ ์ค์
flex-basis ๊ฐ์ด ์ ์ฉ๋์ด ์๋ค๋ฉด width, height ๊ฐ์ ๋ฌด์๋๋ค.
.flex_item {
display: flex;
flex-basis: auto; /* default, ํด๋น ์์ดํ
์ width ๊ฐ์ ์ฌ์ฉํ๋ค. */
0;
50%;
300px;
10rem;
content;
}
- order: ๋ฐฐ์น ์์
.flex_item {
display: flex;
order: 1;
/* -1(์ผ์ชฝ), 0(default), 1(์ค๋ฅธ์ชฝ) */
}
# ๋๋ง์น๋ฉฐ..
์ ๋ง ์ธ์์ผ ํ ๊ฒ ๋ง์์ ํท๊ฐ๋ฆฌ๊ณ ๋ณต์กํ๋ ํ๋ฒ ์ ๋ฆฌํด ๋ณด์๋ค...
ํ๋ฒ ์ญ ์ ๋ฆฌํด ๋ณด๋ ์ดํด๊ฐ ๋๋ ๊ฒ ๊ฐ๋ค.
๋ค์์ ์ด๋ค ๊ฑธ ์ ๋ฆฌํด ๋ณผ๊น!