Front-end/CSS

[CSS3]Flexbox

์œค๋ฏผ_ 2022. 3. 26. 20:35

๐Ÿค” Flex Box

์šฐ๋ฆฌ๊ฐ€ flexbox๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ 4๊ฐ€์ง€ ์‚ฌ๊ณ ๋ฅผ ๊ฐ€์ง€๊ณ  ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

1. ํ”Œ๋ ‰์Šค ์‚ฌ์šฉ (์„ ์–ธ)

2. ๊ฐ€๋กœ ์ •๋ ฌ or ์„ธ๋กœ ์ •๋ ฌ

3. ๋ฌด์กฐ๊ฑด ํ•œ ์ค„ ์•ˆ์— ๋‹ค ์ •๋ ฌ? or ์—ฌ๋Ÿฌ ์ค„ ์ •๋ ฌ?

-----(์ค€๋น„๊ณผ์ •)-----

4. flexbox ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

 

๐Ÿ˜ƒFlexbox ์‚ฌ์šฉ ์ค€๋น„ ๊ณผ์ •

1๏ธโƒฃ ์„ ์–ธ

.flexbox{
  display: flex;
  /* flex | inline-flex */
}

โ— flex๋„ box์˜ type ์ค‘ ํ•˜๋‚˜์ด๋‹ค.

 

flex๋Š” block๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ ์š”์†Œ๋ฅผ ์‰ฝ๊ฒŒ ์ •๋ ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

inlin-flex๋Š” inline-block๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ ์š”์†Œ๋ฅผ ๋” ์‰ฝ๊ฒŒ ์ •๋ ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 

โœจFlex๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•  ๋•Œ๋Š”์ •๋ ฌ์„ ํ•˜๊ณ ์ž ํ•˜๋Š” ์š”์†Œ๋ฅผ ๊ฐ์‹ธ๋Š” ๋ถ€๋ชจํ•œํ…Œ ์ ์šฉ์„ ํ•˜๋ฉด ๋œ๋‹ค.

 

2๏ธโƒฃ ๊ฐ€๋กœ ์ •๋ ฌ or ์„ธ๋กœ ์ •๋ ฌ

.flexbox{
  display: flex;
  flex-direction: row;
  /* row | row-reverse | column | column-revers */
}

๊ฐ€๋กœ ๋ฐฉํ–ฅ ์ •๋ ฌ: row, row-reverse

์„ธ๋กœ ๋ฐฉํ–ฅ ์ •๋ ฌ: column, column-reverse

 

์ฃผ์˜โ—โ—

flex๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ์šฐ๋ฆฌ๋Š” ๋ณด์ด์ง€ ์•Š๋Š” Axis(์ถ•)๊ฐ€ 2๊ฐœ๊ฐ€ (Main axis, Cross axis) ์ƒ๊ธด๋‹ค.

flex-direction๊ฐ’์ด ๋ฌด์—‡์ด๋ƒ์— ๋”ฐ๋ผ Axis๊ฐ€ ์ƒ๊ธฐ๋Š” ํ˜•ํƒœ๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค.

 

Main axis๋Š” ์šฐ๋ฆฌ๊ฐ€ ์„ค์ •ํ•œ ๋ฐฉํ–ฅ๊ณผ ๋™์ผํ•˜๊ฒŒ ์„ค์ •์ด ๋˜๊ณ 

Cross axis๋Š” ์šฐ๋ฆฌ๊ฐ€ ์„ค์ •ํ•œ ๋ฐฉํ–ฅ์— ์ˆ˜์ง์œผ๋กœ ์„ค์ •๋œ๋‹ค.

 

3๏ธโƒฃ ํ•œ ์ค„ ์ •๋ ฌ or ์—ฌ๋Ÿฌ ์ค„ ์ •๋ ฌ

.flexbox {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  /* nowrap | wrap */
}

ํ•œ ์ค„์— ๋‹ค ์ •๋ ฌํ•  ๊ฒƒ์ธ์ง€, ์—ฌ๋Ÿฌ ์ค„์— ๊ฑธ์ณ ์ •๋ ฌํ• ์ง€ ์ •ํ•˜๊ธฐ ์œ„ํ•ด์„  ๊ฐ์‹ธ๊ธฐ(wrap)์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

 

nowrap์€ "๊ฐ์‹ธ์ง€(wrap) ์•Š๊ณ  ์ž์‹์˜ ์‚ฌ์ด์ฆˆ๋ฅผ ์ค„์—ฌ์„œ ํ•œ ์ค„๋กœ ์ •๋ ฌํ•œ๋‹ค."์ด๋ฉฐ

์š”์†Œ์˜ ๊ธฐ๋ณธ ๊ฐ’์€ nowrap์œผ๋กœ ์„ค์ •๋˜์–ด์žˆ๋‹ค.

 

wrap์€ "๊ฐ์‹ธ๊ฒ ๋‹ค(wrap), ํ•œ ์ค„์— ์ •๋ ฌํ•˜๊ธฐ ๊ณต๊ฐ„์ด ๋„‰๋„‰ํ•˜์ง€ ์•Š์„ ์‹œ ์—ฌ๋Ÿฌ ์ค„์„ ๋งŒ๋“ค์–ด ๋ฒ„๋ฆฐ๋‹ค." ๋œป์ด๋‹ค.

 

๐Ÿ‘์—ฌ๊ธฐ๊นŒ์ง€๋Š” flex๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ค€๋น„ ๊ณผ์ •์ด๋‹ค.


4๏ธโƒฃ Flex ์‚ฌ์šฉ

Main axis์™€ Cross axis๋ฅผ ์œ ์˜ํ•˜๋ฉฐ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค!

 

โ— Main axis use โ—

โœ”justify-content

(Flex์š”์†Œ๋“ค์„ ์ค‘์‹ฌ์ถ•(main axis) ์ •๋ ฌ)

 

โ— Coss axis use โ—

โœ” align-items

(Flex์š”์†Œ๋“ค์„ ๋ฐ˜๋Œ€ ์ถ•(cross axis) ์ •๋ ฌ)

โœ”align-content

(์„ธ๋กœ์„  ์ƒ์— ์—ฌ๋ถ„์˜ ๊ณต๊ฐ„์ด ์žˆ๋Š” ๊ฒฝ์šฐ flex ์ปจํ…Œ์ด๋„ˆ ์‚ฌ์ด์˜ ๊ฐ„๊ฒฉ์„ ์กฐ์ ˆ)

 

๐Ÿ“ขwrap์œผ๋กœ ๋‘ ๊ฐœ์˜ ๊ณต๊ฐ„์œผ๋กœ ๋ถ„๋ฆฌ๋˜์—ˆ์„ ๋•Œ

์ „์ฒด ๊ณต๊ฐ„์„ ์˜ฎ๊ธฐ๊ณ ์ž ํ• ๋•Œ๋Š” align-content๋ฅผ ์‚ฌ์šฉํ•˜๊ณ 

๊ฐ๊ฐ ๋ถ„๋ฆฌ๋œ ๊ณต๊ฐ„์„ ์˜ฎ๊ธฐ๊ณ ์ž ํ•  ๋•Œ๋Š” align-items๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด๋œ๋‹ค.

(์ด๋ถ€๋ถ„์ด ํ—ท๊ฐˆ๋ฆฐ๋‹ค๋ฉด items๋ฅผ ๋จผ์ € ์‚ฌ์šฉํ•ด๋ณด๊ณ  content๋„ ์‚ฌ์šฉํ•ด๋ณด๋ฉด ์•Œ ์ˆ˜ ์žˆ๋‹ค!)

.flexbox{
	justify-content: center;
  /* flex-start | flex-end | center | space-beteween | space-around*/
    align-items: flex-end;
  /* flex-start | flex-end | center */
  align-content: flex-end;
  /* flex-start | flex-end | center | space-beteween | space-around*/
}
/*ํ•ด๋‹น key๊ฐ’์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค,*/

 

 

โ— ์ถ”๊ฐ€๋กœ ์ค‘์š”ํ•œ ๊ฒƒ โ—

โœ”order

(flex box์˜ ์ˆœ์„œ ๋ณ€๊ฒฝ)

โœ”flex-flow

(flex-direction+flex-wrap) ๋ฐฉํ–ฅ ๊ฐ์‹ธ๊ธฐ ํ•œ ๋ฒˆ์— ์„ค์ •

'Front-end > CSS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[CSS3] Typography  (0) 2022.03.28
[CSS3]Media Query(๋ฐ˜์‘ํ˜• ์›น)  (0) 2022.03.27
[CSS3]Position  (0) 2022.03.20
[CSS3]Float๋ž€? / Layout ์˜ค๋ฅ˜ ์‹œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•  (0) 2022.03.14
[CSS3]BOX (Block,Inline,Inline Block)  (0) 2022.03.13