CSS Flex - ChoDragon9/posts GitHub Wiki

Flex Basic

Flex๋Š” flex๋ฅผ ์‚ฌ์šฉํ•œ ์ž์‹๋“ค์—๊ฒŒ ๋น„์œจ ํฌ๊ธฐ๋ฅผ ํ• ๋‹นํ•ด์ค๋‹ˆ๋‹ค.

<div style="display: flex">
  <div style="flex: 1">flex(1)</div>
  <div style="flex: 3">flex(3)</div>
  <div style="flex: 2">flex(2)</div>
</div>

ํ—ค๋”๋Š” ์ด๋ ‡๊ฒŒ ์ž‘์„ฑ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

<div style="display: flex">
  <div style="width: 200px">๋กœ๊ณ </div>
  <nav style="flex: 1">
    <ul>
      <li>๋ฉ”๋‰ด1</li>
      <li>๋ฉ”๋‰ด2</li>
      <li>๋ฉ”๋‰ด3</li>
      <li>๋ฉ”๋‰ด4</li>
      <li>๋ฉ”๋‰ด5</li>
    </ul>
  </nav>
</div>

๊ฐ€๋กœ ์ •๋ ฌ

<ul style="display: flex; flex-direction: row">
  <li style="flex: 1">๋ฉ”๋‰ด1</li>
  <li style="flex: 1">๋ฉ”๋‰ด2</li>
  <li style="flex: 1">๋ฉ”๋‰ด3</li>
  <li style="flex: 1">๋ฉ”๋‰ด4</li>
  <li style="flex: 1">๋ฉ”๋‰ด5</li>
</ul>

์ฝ˜ํ…์ธ ๋“ค์„ ์ค‘์•™ ๊ธฐ์ค€์œผ๋กœ ๋ชจ์„ ์ˆ˜ ์žˆ์–ด์š”

<div style="display: flex; justify-content: center">
  <button>Button1</button>
  <button>Button2</button>
  <button>Button3</button>
</div>

์ฝ˜ํ…์ธ ๋“ค์„ ์˜ค๋ฅธ์ชฝ ๊ธฐ์ค€์œผ๋กœ ๋ชจ์„ ์ˆ˜ ์žˆ์–ด์š”

<div style="display: flex; justify-content: flex-end">
  <button>Button1</button>
  <button>Button2</button>
  <button>Button3</button>
</div>

์ฝ˜ํ…์ธ ๋“ค์„ ์™ผ์ชฝ ๊ธฐ์ค€์œผ๋กœ ๋ชจ์„ ์ˆ˜ ์žˆ์–ด์š”

<div style="display: flex; justify-content: flex-start">
  <button>Button1</button>
  <button>Button2</button>
  <button>Button3</button>
</div>

์ฝ˜ํ…์ธ ๋“ค์„ ๊ฐ์ž ๋™์ผํ•œ ์—ฌ๋ฐฑ์œผ๋กœ ์ •๋ ฌํ•  ์ˆ˜ ์žˆ์–ด์š”

<div style="display: flex; justify-content: space-around">
  <button>Button1</button>
  <button>Button2</button>
  <button>Button3</button>
</div>

์ฝ˜ํ…์ธ  ์–‘๋์— ๋ถ™์ด๊ณ , ๋‚จ์€ ์—ฌ๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•  ์ˆ˜ ์žˆ์–ด์š”

<div style="display: flex; justify-content: space-between">
  <button>Button1</button>
  <button>Button2</button>
  <button>Button3</button>
</div>

์ฝ˜ํ…์ธ  ์„ธ๋กœ ์ „์ฒด๋ฅผ ์ฐจ์ง€ํ•  ์ˆ˜ ์žˆ์–ด์š”

<div style="display: flex; align-items: stretch; height: 200px;">
  <button>Button1</button>
  <button>Button2</button>
  <button>Button3</button>
</div>

Flex ๋ ˆ์ด์•„์›ƒ ์ฝ”๋”ฉ

ํ—ค๋” ์ฝ”๋”ฉํ•˜๊ธฐ

<header style="display: flex; max-width: 1000px">
  <figure style="width: 150px">
    <img
      src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
      style="width: 100%">
  </figure>
  <nav style="flex: 1">
    <ul style="display: flex; justify-content: space-between">
      <li><a href="">๋ฉ”๋‰ด1</a></li>
      <li><a href="">๋ฉ”๋‰ด2</a></li>
      <li><a href="">๋ฉ”๋‰ด3</a></li>
      <li><a href="">๋ฉ”๋‰ด4</a></li>
      <li><a href="">๋ฉ”๋‰ด5</a></li>
    </ul>
  </nav>
</header>

1024px

480px

๋ฆฌ์ŠคํŠธ ์ฝ”๋”ฉ

.wrapper {display: flex; justify-content: center}
.list {width: 1140px; display: flex; justify-content: space-between}
.list__item {width: 150px; text-align: center}
<div class="wrapper">
  <div class="list">
    <figure class="list__item">
      <img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" style="width: 100%">
      <figcaption>์•„์ดํ…œ1</figcaption>
    </figure>
    <figure class="list__item">
      <img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" style="width: 100%">
      <figcaption>์•„์ดํ…œ2</figcaption>
    </figure>
    <figure class="list__item">
      <img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" style="width: 100%">
      <figcaption>์•„์ดํ…œ3</figcaption>
    </figure>
    <figure class="list__item">
      <img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" style="width: 100%">
      <figcaption>์•„์ดํ…œ4</figcaption>
    </figure>
  </div>
</div>

โš ๏ธ **GitHub.com Fallback** โš ๏ธ