๐ Flex-Box?
๋ง ๊ทธ๋๋ก ์ด์ด์์ฒญ ํํ ์์ด
๋ถ๋ชจ์์์ ๊ผญ flex-box๋ฅผ ๋ฃ์ด์ค์ผ ์์์์๋ค์ด flex์์ฑ์ ํ์ฉํ ์ ์๋ค
<!--๋ถ๋ชจ์์์ธ div.container๋ฅผ Flex Container๋ผ๊ณ ๋ถ๋ฅด๊ณ -->
<!--๋ถ๋ชจ์์์ ์ ์ฉํด์ผํ๋ ์์ฑ๊ณผ-->
<div class="container">
<!--์์์์์ธ div.item๋ค์ Flex Item์ด๋ผ๊ณ ๋ถ๋ฅธ๋ค-->
<!--์์์์์ ์ ์ฉํด์ผํ๋ ์์ฑ์ด ๋ค๋ฅด๋ค !!-->
<div class="item">helloflex</div>
<div class="item">abc</div>
<div class="item">helloflex</div>
</div>
๐ Flex-Box : Flex Container ๋๋ ๋ถ๋ชจ ์์ฑ
๐ display: flex
.container {
display: flex;
}
item๋ค์ด ๊ฐ์ง ๋ด์ฉ๋ฌผ์ width๋งํผ ๋๋น๋ฅผ ์ฐจ์งํ ์ฑ, inline์์๋ค์ฒ๋ผ ๋ค๋ฅ๋ค๋ฅ๋ถ๋๋ค.
์ฌ๊ธฐ์ container์ height์ ์ค์ ํด์ฃผ๋ฉด item๋ค๋ ๋ถ๋ชจ ๋์ด ๋ฐ๋ผ์ ์ข๋ผ๋ฝ ์์๊ฒ ๋์ฌ์ง๋ค.
๐ display: inline-flex
.container {
display: inline-flex;
}
flex๊ฐ div์ฒ๋ผ ํ๋ฉด ํ ์ค์ ์ก๊ณ ์ดค๋ผ๋ฝ์ด๋ผ๋ฉด
inline-flex๋ item๋คํํ
flex๊ฐ ๋จน์ด๊ณ ๊ทธ ์ค์ ๊ณต๊ฐ ๋จ์ผ๋ฉด ๋ค๋ฅธ ์์๋ค์ ๊ทธ ์ค๋ก ์ฌ๋ผ์ค๊ฒ ํ๋ ^^
inline-block๊ฐ์ ์์ด๋ค.
๐ flex-direction: row / row-reverse / column / column-reverse
item๋ค์ด ๋ฐฐ์น๋๋ ์ถ์ ๋ฐฉํฅ์ ๊ฒฐ์ ํ๋ ์์ฑ.
.container {
flex-direction: row;
}
์ข --> ์ฐ : ๊ฐ๋ก ๋ฐฐ์น
display: flexํ์ ๋ ๊ธฐ๋ณธ๊ฐ
.container {
flex-direction: row-reverse;
}
์ฐ --> ์ข : ๊ฐ๋ก ๋ฐฐ์น
(โป item๋ค ์์๋ ๋ฐ๋ ์ฃผ์)
.container {
flex-direction: column;
}
์ --> ํ : ์ธ๋ก ๋ฐฐ์น
.container {
flex-direction: column-reverse;
}
ํ --> ์ : ์ธ๋ก ๋ฐฐ์น
(โป item๋ค ์์๋ ๋ฐ๋ ์ฃผ์)
๐ flex-wrap: nowrap / wrap / wrap-reverse
container๊ฐ item๋ค์ ํ๋ฉด์์์ ํ ์ค์ ๋ณด์ฌ์ฃผ์ง ๋ชปํ ๋ (ex. ์ฌ์ฉ์๊ฐ ํ๋ฉด์ ์ค์ธ๋ค๊ฑฐ๋ ๋ญ)
item ์ค๋ฐ๊ฟ์ ์ด๋ป๊ฒ ํ ๊ฑด์ง ๊ฒฐ์ ํ๋ ์์ฑ.
.container {
flex-wrap: nowrap;
}
item์ด ํ๋ฉด์์์ ๋์ณ๋ฒ๋ฆฌ๋ฉด ์ฟจํ๊ฒ ์๋ณด์ฌ์ค ํจ์ฐ ~
flex-wrap์ ๊ธฐ๋ณธ๊ฐ.
.container {
flex-wrap: wrap;
}
float / inline-block์ผ๋ก ๋ฐฐ์นํ ์์๋ค๊ณผ ๋น์ทํ๊ฒ ๋์ํ๋ค.
๋์น item์ ์น์ ํ๊ฒ ๋ฐ์ผ๋ก ๋ด๋ ค์ ๋ณด์ฌ์ค๋ค.
.container {
flex-wrap: wrap-reverse;
}
๋์น item์ ์น์ ํ๊ฒ ์๋ก ์ฌ๋ ค์ ๋ณด์ฌ์ค๋ค. ใ
๐ flex-flow: flex-direction flex-wrap
flex-direction ์์ฑ๊ณผ flex-wrap ์์ฑ์ ์ด๋ ๊ฒ ํ๊บผ๋ฒ์ flex-flow ๋ก ๋ฌถ์ด์ค ์๋ ์๋ค.
.container {
flex-flow: row(direction) wrap(wrap);
}
๐ justify-content: flex-start / flex-end / center / space-between / -around / -evenly
๐ align-content: stretch / flex-start / flex-end / center / space-between / -around / -evenly
justify-content --> ์ฃผ ์ถ (main-axis) ์ ์ ๋ ฌ ๋ฐฉ๋ฒ.
align-content --> ๊ต์ฐจ์ถ (cross-axis) ์ ์ ๋ ฌ ๋ฐฉ๋ฒ.
--> ๋ ๋ค flex line์ ์ ๋ ฌํ๋ค.
.container {
display: flex;
justify-content: flex-start;
}
.container {
display: flex;
flex-direction: column;
align-content: flex-start;
}
์์ดํ ์ค ๊ทธ๋๋ก ~ ์ข์ธก ์ ๋ ฌ
.container {
display: flex;
justify-content: flex-end;
}
.container {
display: flex;
flex-direction: column;
align-content: flex-end;
}
์์ดํ ์ค ๊ทธ๋๋ก ~ ์ฐ์ธก ์ ๋ ฌ
(โป item์์ ์๋ฐ๋!)
.container {
display: flex;
justify-content: center;
}
.container {
display: flex;
flex-direction: column;
align-content: center;
}
์์ดํ ์ค ๊ทธ๋๋ก ~ ๊ฐ์ด๋ฐ ์ ๋ ฌ
โ ์ฃผ์์ โ
์น ๋ธ๋ผ์ฐ์ ๋ width๋ ๋ณดํต (์์ฐ)๊ณ ์ ๋์ด์๋ค.
๊ทธ๋ฌ๋ height๋ height๊ฐ์ ์ฃผ์ง ์์ผ๋ฉด, content ์์ฒด์ ๋์ด๋ฅผ ๋ฐ๋ฅธ๋ค.
01
( content์ height๊ฐ์ ์ฃผ์ง ์์๋ค๊ณ ๊ฐ์ )
flex-direction์ด row์ผ๋ justify-content๋ ๋ค์ํ ๋ณํ๋ฅผ ์ค ์ ์์ง๋ง, align-content๋ ์ ์ฉ๋์ง ์๋๋ค.
flex-direction์ด column์ผ๋๋ height๊ฐ์ ๋ถ์ฌ๋ก, justify-content์ align-content ๋ชจ๋ ์ ์ฉ๋์ง ์๋๋ค.
๋ด๊ฐ ์์ํ๋๋๋ก ์ ๋ ์์ง์ด์ง ์์๋ค.
02
( container์ flex-wrap๊ฐ์ ์ฃผ์ง ์์๋ค๊ณ ๊ฐ์ )
flex-direction์ด row์ผ๋ justify-content๋ ์ ์ ์ฉ๋์ง๋ง, align-content๋ ์ ์ฉ๋์ง ์๋๋ค.
wrap๊ฐ์ด ์์ผ๋ฉด item์ ์์น๊ฐ ๊ฐ๋ก์ถ์ ๊ณ ์ ๋์ด ์ธ๋ก์ถ์ ๋ณํ๋ฅผ ์ค ์ ์๋ ์ฌ์ง๊ฐ ์ฌ๋ผ์ง๋ค. --> flex-line์ด ํ๋์ด๊ธฐ์ !!
์ฆ wrap๊ฐ์ ์ ์ฉํ๊ณ item์ด ์ ์ด๋ 2์ค ์ด์์ ๋์ด์ผ align-content๋ฅผ ์ ์ฉํ์ ๋ ํจ๊ณผ๊ฐ ๋ํ๋๋ค.
flex-direction์ด column์ผ๋๋ ๋ง์ฐฌ๊ฐ์ง๋ค.
column์ ํนํ wrap๊ฐ์ ์ฃผ์ง ์์ผ๋ฉด ๋ฏธ๋๋ ์ํ๋ค. justify-content, align-content ๋ชจ๋ ์ ์ฉ๋์ง ์์ ใ !
์ ์ด์ ์์ง์ผ๋ก ๋ฐ๋ ค์๋ item๋ค์ด๊ธฐ์ height๊ฐ๊ณผ wrap๊ฐ์ ๊ผญ ์ค์ผ ์ํ๋๋๋ก ์๋ํ๋ค.
/* row & column */
/* ์ข์ฐ ๊ท ์ผ ์ ๋ ฌ */
.container {
height: 500px;
display: flex;
justify-content: space-between;
}
.container {
height: 500px;
display: flex;
flex-flow: column wrap;
align-content: space-between;
}
/* row & column */
/* ์ํ ๊ท ์ผ ์ ๋ ฌ */
.container {
height: 500px;
flex-flow: row wrap;
align-content: space-between;
}
.container {
height: 500px;
display: flex;
flex-flow: column wrap;
justify-content: space-between;
}
flex-direction: row / column
--> item๋ค ์ฌ์ด(between)์ ๊ท ๋ฑํ ๊ฐ๊ฒฉ์ ๋ง๋ค์ด ์ค๋ค
--> ํ๋ฉด์ width๊ฐ ์ค์ฌ์ผ๋ก ํ๊ธฐ๋๋ฌธ์ ์ ์ฌ์ด๋์ item์ด ํ๋ฉด ๋์ ๋ถ์ด๋ฒ๋ฆฐ๋ค ใ ใ
/* row & column */
/* ์ข์ฐ ๊ท ์ผ ์ ๋ ฌ */
.container {
height: 500px;
display: flex;
justify-content: space-around;
}
.container {
height: 500px;
display: flex;
flex-flow: column wrap;
align-content: space-around;
}
/* row & column */
/* ์ํ ๊ท ์ผ ์ ๋ ฌ */
.container {
height: 500px;
flex-flow: row wrap;
align-content: space-around;
}
.container {
height: 500px;
display: flex;
flex-flow: column wrap;
justify-content: space-around;
}
flex-direction: row / column
--> item๋ค ๋๋ (around)์ ๊ท ๋ฑํ ๊ฐ๊ฒฉ์ ๋ง๋ค์ด ์ค๋ค
--> item๋๋ ์ ๋๊ฐ์ ๊ฐ๊ฒฉ์ ์ค์ ๋์ฐ๊ธฐ๋๋ฌธ์ ์ ์ฌ์ด๋์ item์ 1/2๋งํผ ๋ ๋์์ง๋ค ใ ใ
/* row & column */
/* ์ข์ฐ ๊ท ์ผ ์ ๋ ฌ */
.container {
height: 500px;
display: flex;
justify-content: space-evenly;
}
.container {
height: 500px;
display: flex;
flex-flow: column wrap;
align-content: space-evenly;
}
/* row & column */
/* ์ํ ๊ท ์ผ ์ ๋ ฌ */
.container {
height: 500px;
flex-flow: row wrap;
align-content: space-evenly;
}
.container {
height: 500px;
display: flex;
flex-flow: column wrap;
justify-content: space-evenly;
}
flex-direction: row / column
--> ๊ณต๋ฐฑ๊ณผ item์ ๋๋ฏธ๋ ธ์ฒ๋ผ ์ผ๋ ฌ๋ก ์ธ์ด ๋ชจ์ต์ ๋ง๋ค์ด์ค๋ค
--> item์ด ํ๋ฉด ๋์ ๋ถ์ง๋ ์๊ณ , ์ ๋งคํ๊ฒ 1/2๋ง ๋์์ ธ์์ง๋ ์๋ค
--> ๊ฐ์ธ์ ์ผ๋ก ๋๊ฒ ์ข์ํ๋๋ฐ.. IE์ Edge์์๋ ์ง์์ด ์๋๋ค
'Front-end > CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
styled-component, useState ์ฌ์ฉํด์ Modal์ฐฝ ๋ง๋ค๊ธฐ (0) | 2021.09.14 |
---|---|
CSS font-size ์์ฑ (0) | 2021.08.09 |
CSS flex-box ์ ๋ถ๋ชจ ์์ฑ align-items (0) | 2021.08.08 |
CSS padding (0) | 2021.07.28 |
CSS box-sizing: content-box์ border-box์ ์ฐจ์ด (0) | 2021.07.27 |
๋๊ธ