
๋ณธ์ธ์ ์ํด ์์ฑํ๋ ๊ฒ์๊ธ์ด๊ธฐ ๋๋ฌธ์ ๊ฐ๋จํ๊ฒ ์ฌ์ฉ๋ฒ๋ง ์ ๋ฆฌํ๊ฒ ์ต๋๋ค.
flex-box: display: flex๋ฅผ ์ ์ฉํ ํ๊ทธ๋ฅผ ์๋ฏธํฉ๋๋ค.flex๋ฅผ inlineํํ๋ก ์ ์ฉ์ํจ ๊ฒ์
๋๋ค.
์๋ฅผ ๋ค๋ฉด <div>๊ฐ์ ๊ฒฝ์ฐ์๋ display: block์ด๋ฏ๋ก ํ ์ค ์ ์ฒด๋ฅผ ์ฐจ์งํฉ๋๋ค.
display: flex์ flex-box์ํ๋ก display: block์ฒ๋ผ ํ ์ค ์ ์ฒด๋ฅผ ์ฐจ์งํฉ๋๋ค.
ํ์ง๋ง display: inline-flex๊ฐ์ ๊ฒฝ์ฐ์๋ inline-block์ฒ๋ผ ๋ณธ์ธ ํฌ๊ธฐ๋งํผ๋ง width๋ฅผ ์ฐจ์งํ๊ฒ ๋๋ค.
ํ๋ ์ค๋ฐ์ค์ ๋ฉ์ธ์ถ์ ๊ฒฐ์ ํฉ๋๋ค. ( ์ ๋ ฌ ๋ฐฉํฅ์ ์ง์ )
row: ์ข์ธก -> ์ฐ์ธก ( ๊ธฐ๋ณธ๊ฐ )row-reverse: ์ฐ์ธก -> ์ข์ธกcolumn: ์ -> ์๋column-reverse: ์๋ -> ์.flex-box {
display: flex;
flex-direction: row;
flex-direction: column;
flex-direction: row-reverse;
flex-direction: column-reverse;
}
flex-box์ ์ค๋๊น ์ฒ๋ฆฌ๋ฅผ ๊ฒฐ์ ํฉ๋๋ค. ( ๋ฐ์ค์ ํฌ๊ธฐ๋ณด๋ค ์์ดํ
๋ค์ ํฌ๊ธฐ๊ฐ ๋ ํด ๊ฒฝ์ฐ )
flex-box์ ํฌ๊ธฐ๋ณด๋ค ์์ดํ
๋ค์ ํฌ๊ธฐ๊ฐ ๋ ํด ๊ฒฝ์ฐnowrap: ์์ดํ
์ ๋์ด๋ฅผ ๋์ ( ๊ธฐ๋ณธ๊ฐ )wrap: ์์ดํ
์ ๋ค์ ๋ผ์ธ์ผ๋ก ๋๊นwrap-reverse: ์์ดํ
์ ์ญ์์ผ๋ก ๋ค์ ๋ผ์ธ์ผ๋ก ๋๊น.flex-box {
display: flex;
flex-wrap: nowrap;
flex-wrap: wrap;
flex-wrap: wrap-reverse;
}
flex-direction๊ณผ flex-flow์ ์ถ์ฝ ๋ฌธ๋ฒ์
๋๋ค.
.flex-box {
display: flex;
flex-flow: row nowrap;
}
๋ฉ์ธ์ถ/๊ต์ฐจ์ถ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ ๋ฐฉ๋ฒ์ ๊ฒฐ์ ํ๋ ์์ฑ์ ๋๋ค.
align-content์ ๊ฒฝ์ฐ flex-flow: row wrap;๊ฐ์ ์ํ์ผ ๋flex-direction: row์ผ ๊ฒฝ์ฐ ์์์ ์ ์ข์ธก
flex-direction: column์ผ ๊ฒฝ์ฐ ์์์ ์ ์
์๋ ์ค๋ช
์ flex-direction: row๋ฅผ ๊ธฐ์ค์ผ๋ก ์ ๋ฆฌํ๊ฒ ์ต๋๋ค.
stretch: ๋ชจ๋ ๋์ผํ ๋น์จ์ ํฌ๊ธฐ๋ฅผ ๊ฐ์ง๊ณ ๋์ด๋จ ( ๊ธฐ๋ณธ๊ฐ )flex-start: ์์ดํ
๋ค์ ํฌ๊ธฐ์ ๋ง๊ฒ ์์์ ์ข์ธก์ ๋ถ์center: ์ ์ฒด width์์ ์์ดํ
์ ๋์ดํ๊ณ ์ ์ฒด์ ์ค๊ฐ๊ณผ ๋ฐฐ์นํ ์์ดํ
๋ค์ ์ค๊ฐ์ ์์น๋ฅผ ๋์ผํ๊ฒ ๋ง๋ฆflex-end: ์์ดํ
๋ค์ ํฌ๊ธฐ์ ๋ง๊ฒ ์์์ ์ฐ์ธก์ ๋ถ์space-between: ์์ดํ
๋ค์ ์ข์ธก, ์ฐ์ธก ๋์ ๋ถ์ฌ์ ๋์ผํ ๊ฐ๊ฒฉ์ผ๋ก ๋จ์ดํธ๋ฆผspace-around: ์์ดํ
๋ค์ ๋ชจ๋ ๊ฐ๊ฐ ๋์ผํ ๊ฐ๊ฒฉ์ ๊ฐ์งspace-evenly: ์์ดํ
๋ค์ ์ค๋ณต๋ ๊ฐ๊ฒฉ์ ์ ์ธํ๊ณ ๋์ผํ ๊ฐ๊ฒฉ์ผ๋ก ๋จ์ดํธ๋ฆผ.flex-box {
display: flex;
justify-content: flex-start;
justify-content: flex-end;
justify-content: center;
justify-content: space-between;
justify-content: space-around;
justify-content: space-evenly;
}
๊ต์ฐจ์ถ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ ๋ฐฉ๋ฒ์ ๊ฒฐ์ ํ๋ ์์ฑ์ ๋๋ค.
stretch: ์์ดํ
์ด ์ ์ฒด ๋์ด์ ๋ง๊ฒ ๋์ด๋จ ( ๊ธฐ๋ณธ๊ฐ )flex-start: ๊ธฐ๋ณธ ๋์ด๋งํผ ๊ฐ์ง๊ณ ์์ ์ง์ ์ ๋ถ์flex-end: ๊ธฐ๋ณธ ๋์ด๋งํผ ๊ฐ์ง๊ณ ๋ ์ง์ ์ ๋ถ์center: ๊ธฐ๋ณธ ๋์ด๋งํผ ๊ฐ์ง๊ณ ์ค๊ฐ์ ๋ถ์baseline: ํ
์คํธ์ ์๋ ๋ผ์ธ์ ๋ง์ถฐ์ ๋ฐฐ์นํจ.flex-box {
display: flex;
align-items: stretch;
align-items: flex-start;
align-items: flex-end;
align-items: center;
align-items: baseline;
}
์์ดํ ์ ์ต์ ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ ํฉ๋๋ค.
width์ ๋ค๋ฅธ์ ์ ์ ์ฐํจ์ ์์ต๋๋ค.
flex-basis: 100px;์ 100px์ ์ด๊ณผํ ๊ฒฝ์ฐ ์ ์ฐํ๊ฒ ๋ณธ์ธ ํฌ๊ธฐ๋งํผ ๋์ด๋์ง๋ง width: 100px;๋ ์ ์งํ๊ฒ 100px๋งํผ๋ง ์ฐจ์งํฉ๋๋ค.
auto, px, rem, cm ๋ฑ ๋จ์ ๊ฐ ๋ชจ๋ ์ฌ์ฉ ๊ฐ๋ฅํจ
auto.flex-box {
display: flex;
}
.flex-item {
flex-basis: auto;
flex-basis: 100px;
}
์์ดํ ์ ๋ฐฐ์นํ๊ณ ๋ ๋ค ๋จ์ ๊ณต๊ฐ์ ์์ดํ ์ด ๊ฐ์ง ๋น์จ์ ๊ฒฐ์ ํฉ๋๋ค.
์ผ๋ฐ์ ์ธ ์์ฐ์๊ฐ ๋ค์ด๊ฐ๊ณ ๋ค์ด๊ฐ ์์ฐ์์ ๋น์จ์ ๋งํผ ๋จ์ ๊ณต๊ฐ์ ํฌ๊ธฐ๋ฅผ ํ ๋น๋ฐ๋๋ค.
.flex-box {
display: flex;
}
.flex-item:nth-child(1) {
flex-grow: 1;
}
.flex-item:nth-child(2) {
flex-grow: 2;
}
์์ดํ
์ด ์ค์ด๋๋ ๋น์จ์ ๊ฒฐ์ ํฉ๋๋ค.
๊ธฐ๋ณธ๊ฐ์ด 1์ด๋ฉฐ flex-grow๊ณผ ๋ฐ๋ ์ญํ ์ ํฉ๋๋ค.
์์ดํ
์ด ๋ณธ์ธ ์๋ ํฌ๊ธฐ๋ณด๋ค ์์์ง๊ฒ ๋ ๊ฒฝ์ฐ์ ๊ฐ์ flex-box์ ์์ดํ
๋ค์ flex-shrink๊ฐ์ ๋น์จ์ ๊ธฐ์ค์ผ๋ก ์์์ง๊ฒ ๋ฉ๋๋ค.
์์ดํ ์ด ๋ณธ์ธ์ ์๋ ํฌ๊ธฐ๋ณด๋ค ์์์ง๊ฒ ๋์ ๋ ์ ์ฉ๋๋ ๋ฐฉ์์ด๋ผ
flex-wrap: nowrap์ด์ด์ผ ์ ์ฐํ ๊ฒฐ๊ณผ๋ฅผ ๋ณผ ์ ์์ต๋๋ค
.flex-box {
display: flex;
flex-basis: 300px;
}
.flex-box > li:nth-child(1) {
background: red;
flex-grow: 1;
flex-basis: 300px;
flex-shrink: 0; /* ๊ธฐ๋ณธ๊ฐ 1 */
}
.flex-box > li:nth-child(2) {
background: green;
flex-grow: 1;
}
flex-grow, flex-shrink, flex-basis์ ์ถ์ฝ ๋ฌธ๋ฒ
flex-basis์๋ตํ ๊ฒฝ์ฐ์๋ 0%๊ฐ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ ์ฉ๋๋ค.
.flex-box {
display: flex;
flex-basis: 300px;
}
.flex-box > li:nth-child(1) {
background: red;
flex: 1 0 300px; /* ์๋ 3๊ฐ์ ์ถ์ฝ ๋ฌธ๋ฒ */
flex-grow: 1; /* ๊ธฐ๋ณธ๊ฐ 0 */
flex-shrink: 0; /* ๊ธฐ๋ณธ๊ฐ 1 */
flex-basis: 300px; /* ๊ธฐ๋ณธ๊ฐ auto */
}
.flex-box > li:nth-child(2) {
background: green;
flex-grow: 1;
}
align-items, justify-content์ ๊ฐ์ธ ์์ฑ์ ์ง์ ํจ