๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“Œ Language/HTML&CSS

[CSS] Flex ์†์„ฑ ์•Œ์•„๋ณด๊ธฐ (List of flex properties)

by Fomagran ๐Ÿ’ป 2022. 2. 22.
728x90
๋ฐ˜์‘ํ˜•

 

์•ˆ๋…•ํ•˜์„ธ์š” Foma ๐Ÿ’ป ์ž…๋‹ˆ๋‹ค.

 

์˜ค๋Š˜์€ CSS์—์„œ ์‰ฝ๊ฒŒ ๋ ˆ์ด์•„์›ƒ์„ ํ•  ์ˆ˜ ์žˆ๋Š” Flex์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๋ฐ”๋กœ ์‹œ์ž‘ํ• ๊ฒŒ์š”~


flex-basis

 

ํ”Œ๋ ‰์Šค ์•ˆ์— ์žˆ๋Š” ์š”์†Œ์˜ ๊ธฐ๋ณธ ํฌ๊ธฐ๋ฅผ ์„ค์ •ํ•˜๋Š” ์†์„ฑ

 

<!DOCTYPE html>
<html>
<head>
<style>
#main {
  width: 300px;
  height: 100px;
  border: 1px solid #c3c3c3;
  display: flex;
}

#main div {
  flex-grow: 0;
  flex-shrink: 0;
  flex-basis: 50px;
}

#main div:nth-of-type(2) {
  flex-basis: 100px;
}
</style>
</head>
<body>

<div id="main">
  <div style="background-color:coral;">50px</div>
  <div style="background-color:lightblue;">100px</div>
  <div style="background-color:khaki;">50px</div>
</div>
</body>
</html>

 

 

 

1. px์ด๋‚˜ em์œผ๋กœ ์ง์ ‘ ์ง€์ •ํ•˜๊ธฐ

 

ํŒŒ๋ž€์ƒ‰ ๋ฐ•์Šค 300px๋กœ ๋Š˜๋ฆฌ๊ธฐ

 

(์—ฌ๊ธฐ์„œ nth-of-type(2)๋Š” flex์•ˆ์— ์žˆ๋Š” ์š”์†Œ ์ค‘ 2๋ฒˆ์งธ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.)

 

flex-basis: 300px;

 

 

ํ•˜์ง€๋งŒ ๊ธ€์ž์˜ ๊ธธ์ด๋ณด๋‹ค ์งง๊ฒŒ ์ง€์ •ํ–ˆ์„ ๋• ๊ธ€์ž ๊ธธ์ด ๋งŒํผ๋งŒ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค.

 

2. ํ‚ค์›Œ๋“œ๋กœ ์ง€์ •ํ•˜๊ธฐ

 

ํ‚ค์›Œ๋“œ๋กœ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ ํŒŒ๋ž€์ƒ‰ ๋ฐ•์Šค์˜ ํ…์ŠคํŠธ ๊ธธ์ด๋ฅผ ๋Š˜๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 <div style="background-color:lightblue;">
    abcdefg
    hijklmnop
    qrstuvwxyz
 </div>

 

1. fill

 

ํ…์ŠคํŠธ ๊ธธ์ด์— ๋”ฑ ๋งž๊ฒŒ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค.

 

flex-basis: fill;

 

2. max-content

 

์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ๊ณต๊ฐ„์ด ๋ฌดํ•œํ•  ๋•Œ ํ…์ŠคํŠธ ๊ธธ์ด์— ๊ฐ€์žฅ ์ด์ƒ์ ์ธ ํฌ๊ธฐ๋กœ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค. (์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„˜์–ด์„œ๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅ)

 

flex-basis: max-content;

 

3. min-content

 

ํ…์ŠคํŠธ๊ฐ€ ์ž˜๋ฆฌ์ง€ ์•Š๋Š” ์„ ์—์„œ ์ตœ์†Œ์น˜๋กœ ์ค„์–ด๋“ญ๋‹ˆ๋‹ค.

 

flex-basis: min-content;

 

4. fit-content

 

์ปจํ…Œ์ด๋„ˆ ํฌ๊ธฐ์™€ ํ…์ŠคํŠธ ๊ธธ์ด์— ๋”ฐ๋ผ ์ด์ƒ์ ์œผ๋กœ ํฌ๊ธฐ๋กœ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค.

 

flex-basis: fit-content;

 

5. auto

 

ํ…์ŠคํŠธ์˜ ๊ธธ์ด์˜ ์ตœ๋Œ€ ๊ธธ์ด์— ๋”ฐ๋ผ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค.

 

flex-basis: auto;

 

๋‹จ, auto๋ฅผ ์ง€์ •ํ•˜๊ณ  width๊ฐ’์„ ์ง€์ •ํ–ˆ์„ ๊ฒฝ์šฐ width๊ฐ’์œผ๋กœ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค.

 

  flex-basis: auto;
  width:10px;

 

6. content

 

์ปจํ…์ธ ์˜ ๊ธธ์ด์— ๋”ฐ๋ผ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค.

 

 flex-basis: content;

 

 

content๋Š” auto์™€ ๋‹ค๋ฅด๊ฒŒ width๊ฐ’์„ ์ง€์ •ํ•ด๋„ ์ปจํ…์ธ ์˜ ๊ธธ์ด๋กœ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.

 

 flex-basis: content;
 width: 10px;

 


flex-direction

 

์ปจํ…Œ์ด๋„ˆ ๋‚ด์˜ ์•„์ดํ…œ์„ ๋ฐฐ์น˜ํ•  ๋•Œ ์‚ฌ์šฉํ•  ๋ฐฉํ–ฅ์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ

 

(์•„๋ฌด๊ฒƒ๋„ ์ง€์ •ํ•˜์ง€ ์•Š์•˜์„ ๋•Œ ๊ธฐ๋ณธ์€ row์ž…๋‹ˆ๋‹ค.)

 

1. row

 

 flex-direction:row;

2. row-revese

 

 flex-direction: row-revese;

 

3. column

 

 flex-direction: column;

 

4. column-reverse

 

 flex-direction: column-reverse;

 


flex-grow

 

์ปจํ…Œ์ด๋„ˆ ๋‚ด์—์„œ ํ• ๋‹น ๊ฐ€๋Šฅํ•œ ๊ณต๊ฐ„์˜ ์ •๋„๋ฅผ ๋น„์œจ๋กœ ์„ค์ •ํ•˜๋Š” ์†์„ฑ

 

A,C = 1 , B = 2 (1:2:1)

 

#main div {
  flex-grow: 1;
}

#main div:nth-of-type(2) {
  flex-grow:2
}


flex-shrink

 

์ปจํ…Œ์ด๋„ˆ์˜ ๊ฐ’์ด ์ถฉ๋ถ„ํ•˜์ง€ ์•Š์„ ๋•Œ ๋จผ์ € ์ค„์–ด๋“ค ๋น„์œจ์„ ์„ค์ •ํ•˜๋Š” ์†์„ฑ

 

์ „์ฒด ์ปจํ…Œ์ด๋„ˆ width๊ฐ€ 300px์ด๊ณ  ๊ฐ ์•„์ดํ…œ์˜ width๊ฐ€ 150px์ผ ๋•Œ 

 

A,C = 1 , B = 2

 

#main div {
  flex-basis: 150px;
  flex-shrink: 1;
}

#main div:nth-of-type(2) {
  flex-basis: 150px;
  flex-shrink:2
}

 

 

๋งŒ์•ฝ ์ „์ฒด ์ปจํ…Œ์ด๋„ˆ width๊ฐ€ ์ถฉ๋ถ„ํ•˜๋‹ค๋ฉด ์ ์šฉ ์•ˆ๋จ.

 

#main div {
  flex-basis: 100px;
  flex-shrink: 1;
}

#main div:nth-of-type(2) {
  flex-basis: 100px;
  flex-shrink:2
}


flex

 

์ปจํ…Œ์ด๋„ˆ ์•ˆ์˜ ์•„์ดํ…œ์ด ์ฐจ์ง€ํ•˜๋Š” ๊ณต๊ฐ„์— ๋งž์ถ”๊ธฐ ์œ„ํ•ด ํฌ๊ธฐ๋ฅผ ํ‚ค์šฐ๊ฑฐ๋‚˜ ์ค„์ด๋Š” ๋ฐฉ๋ฒ•์„ ์„ค์ •ํ•˜๋Š” ์†์„ฑ

 

flex๋Š” ์œ„์—์„œ ์„ค๋ช…ํ•œ flex-basis,flex-grow,flex-shrink๋ฅผ ํ•œ๋ฒˆ์— ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

1. 1๊ฐ€์ง€ ์„ค์ •ํ•œ ๊ฒฝ์šฐ

 

์ˆซ์ž๋กœ ์„ค์ •ํ•œ ๊ฒฝ์šฐ๋Š” flex-grow๋ฅผ ์„ค์ •ํ•œ ๊ฒƒ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

#main div {
  flex:1
}

#main div:nth-of-type(2) {
  flex:2
}

 

 

px์ด๋‚˜ em ๋˜๋Š” %๋กœ ์„ค์ •ํ•œ ๊ฒฝ์šฐ๋Š” flex-basis์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

#main div {
  flex:30px
}

#main div:nth-of-type(2) {
  flex:50px
}

 

 

2. 2๊ฐ€์ง€ ์„ค์ •ํ•œ ๊ฒฝ์šฐ

 

์ฒซ ๋ฒˆ์งธ ๊ฐ’์€ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. (px or em or % ๋ถˆ๊ฐ€)

 

์ˆซ์ž์™€ ๋‹จ์œ„๋กœ ์„ค์ •ํ•œ ๊ฒฝ์šฐ๋Š” flex-grow์™€ flex-basis ์ž…๋‹ˆ๋‹ค.

 

#main div {
  flex:1 50px
}

#main div:nth-of-type(2) {
  flex:2 50px
}

์ˆซ์ž์™€ ์ˆซ์ž๋กœ ์„ค์ •ํ•œ ๊ฒฝ์šฐ flex-grow์™€ flex-shrink๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

 

#main div {
  flex:1 1
}

#main div:nth-of-type(2) {
  flex:2 2
}

 

3. 3๊ฐ€์ง€๋กœ ์„ค์ •ํ•œ ๊ฒฝ์šฐ

 

flex-grow flex-shrink flex-basis๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

 

#main div {
  flex:1 1 150px
}

#main div:nth-of-type(2) {
  flex:2 2 150px
}

 


flex-wrap

 

์•„์ดํ…œ๋“ค์ด ๊ฐ•์ œ๋กœ ํ•œ์ค„์— ๋ฐฐ์น˜๋˜๊ฒŒ ํ•  ๊ฒƒ์ธ์ง€, ๊ฐ€๋Šฅํ•œ ์˜์—ญ ๋‚ด์—์„œ ๋ฒ—์–ด๋‚˜์ง€ ์•Š๊ณ  ์—ฌ๋Ÿฌ ํ–‰์œผ๋กœ ๋‚˜๋ˆ„์–ด ํ‘œํ˜„ํ•  ๊ฒƒ์ธ์ง€ ๊ฒฐ์ •ํ•˜๋Š” ์†์„ฑ

 

1. wrap

 

#main {
  width: 300px;
  height: 100px;
  border: 1px solid #c3c3c3;
  display: flex;
  flex-wrap: wrap;
}

#main div {
  flex:1 1 150px
}

#main div:nth-of-type(2) {
  flex:2 2 150px
}

 

2. nowrap

 

...
flex-wrap: nowrap;
...

 

3. wrap-reverse

 

...
flex-wrap: wrap-reverse;
...


flex-flow

 

flex-direction๊ณผ flex-wrap์„ ํ•œ๋ฒˆ์— ์„ค์ •ํ•˜๋Š” ์†์„ฑ

 

ํ˜•์‹์€ flex-direction์„ ๋จผ์ € ์“ฐ๊ณ  flex-wrap์„ ๋’ค์— ์จ์•ผํ•ฉ๋‹ˆ๋‹ค.

 

1. row wrap

 

...
flex-flow:row wrap;
...

 

 

2. row nowrap

 

...
flex-flow:row nowrap;
...

 

 

3. row wrap-revese

 

...
flex-flow:row wrap-reverse;
...

 

 

4. column wrap

 

...
flex-flow:column wrap;
...

 

 

 

5. column nowrap

 

...
flex-flow:column nowrap;
...

 

6. column wrap-reverse

 

...
flex-flow:column wrap-reverse;
...

 

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€