Grid System

HTML / CSS ๋ฐฐ์น˜

  • ๋ฐฐ์น˜ ํ•ต์‹ฌ

    : ์™ผ์ชฝ ์œ„์— ์Œ“์ธ๋‹ค (๋ฐ•์Šค๋ชจ๋ธ)

    • ์–ด๋–ป๊ฒŒ?

      • block

      • inline

  • ๋ฐฐ์น˜ ํ๋ฆ„์„ ๋ฐ”๊พธ๋Š” ๋ฐฉ๋ฒ•

    • float

    • position

      • flex: flexible box

flex

flex ์ด์ „์—๋Š” ๋ฐฐ์น˜๋ฅผ ์œ„ํ•ด์„œ float , position ์ง€์ •์„ ํ•ด์•ผํ–ˆ์Œ

img

flex ์ฃผ์š” ๊ฐœ๋…

  • container

  • item

<style>
    .container {
        display: flex;
    }
</style>


<div class="container">
    <div class="item"></div>
    <div class="item"></div>
</div>

  • ์ถ•

    • main axis

      : ์ฃผ์ถ•

      • flex-direction: row; ์ผ ๋•Œ ๊ฐ€๋กœ ์ถ•

      • flex-direction: column; ์ผ ๋•Œ ์„ธ๋กœ ์ถ•

      • flex-direction: column-reverse; ์ผ ๋•Œ ๋ฐ‘์—์„œ ์œ„๋กœ ์˜ฌ๋ผ๊ฐ€๋Š” ์„ธ๋กœ ์ถ•

      • flex-direction: row-reverse; ์ผ ๋•Œ ์˜ค๋ฅธ์ชฝ์—์„œ ์™ผ์ชฝ์œผ๋กœ ๊ฐ€๋Š” ๊ฐ€๋กœ ์ถ•

    • cross axis

      : ํฌ๋กœ์Šค์ถ•

flex ์ •์˜ ์‹œ

  1. ๋ชจ๋“  ํ•ญ๋ชฉ๋“ค์€ main axis (์ฃผ์ถ•)์„ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜๊ฐ€ ์‹œ์ž‘๋จ

    • ๊ธฐ๋ณธ์€ row

    • ๋งŒ์•ฝ, row-reverse๋กœ ์ง€์ •ํ•˜๊ฒŒ ๋˜๋ฉด, ์˜ค๋ฅธ์ชฝ ๋๋ถ€ํ„ฐ ๋ฐฐ์น˜๊ฐ€ ์‹œ์ž‘๋จ

  2. ๋ชจ๋“  item์€ ๊ธฐ๋ณธ์ ์œผ๋กœ row๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜๋จ

    • flex-direction : row ๊ฐ’์œผ๋กœ ๊ธฐ๋ณธ ์„ค์ • ๋จ

  3. ๋ชจ๋“  item์€ cross axis๋ฅผ ๋ชจ๋‘ ์ฑ„์šด๋‹ค

    • ๋†’์ด๋ฅผ ๋ชจ๋‘ ์ฑ„์šด๋‹ค

      • align-items: stretch; ๊ฐ€ ๊ธฐ๋ณธ๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ

  4. ๋ชจ๋“  item์€ ๋ณธ์ธ์˜ ๋„ˆ๋น„ ํ˜น์€ content ์˜์—ญ๋งŒํผ ๋„ˆ๋น„๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค

    • ๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ, ๋ณธ์ธ์ด ์ง€์ •๋ฐ›์€ ๋„ˆ๋น„๋ณด๋‹ค ์ž‘์„ ์ˆ˜ ์žˆ๋‹ค

      • flex-wrap: nowrap ์ด ๊ธฐ๋ณธ๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ

      • ex) ์ „์ฒด item์˜ ๋„ˆ๋น„์˜ ํ•ฉ์ด container์˜ ๋„ˆ๋น„๋ณด๋‹ค ์ž‘์„ ๋•Œ ๋ณด๋‹ค ์ž‘์„ ๋•Œ

  5. ๊ฐ ์˜์—ญ์€ content ํฌ๊ธฐ / ๋„ˆ๋น„๋งŒํผ ์˜์—ญ์„ ์ฐจ์ง€ํ•จ

    • ๋” ์ž‘์„ ์ˆ˜๋„ ์žˆ์Œ!

  6. ๋ชจ๋“  ์˜์—ญ์€ cross axis (ํฌ๋กœ์Šค ์ถ•)์„ ์ฑ„์šฐ๊ณ  ์žˆ๋Š” ๋ชจ์Šต์ž„

image-20200323112512435

flex ์†์„ฑ

1. flex-wrap

  • ๊ธฐ๋ณธ ๊ฐ’ nowrap

    • ํ•œ ์ค„์•ˆ์— ๋ฌด์กฐ๊ฑด ๋‹ด๋Š”๋‹ค

  • wrap

    • ๊ฐ๊ฐ์˜ ๋„ˆ๋น„๋งŒํผ ๊ฐ€์ง€๊ฒŒ ๋˜๊ณ  ์ž๋ฆฌ๊ฐ€ ์—†์œผ๋ฉด ๋ฐ‘์œผ๋กœ ๋‚ด๋ ค๊ฐ

    • ํ˜๋Ÿฌ ๋„˜์น˜์ง€ ์•Š๊ฒŒ ์„ค์ •ํ•ด์ฃผ๋Š” ๊ฒƒ!

  • wrap-reverse

    • Items wrap round to additional lines in reverse

2. flex-grow

flex-grow๋Š” ๋‚จ์€ ๋„ˆ๋น„๋ฅผ ๊ฐ๊ฐ ๋น„์œจ๋กœ ๋‚˜๋ˆ ์„œ ๊ฐ€์ ธ๊ฐ

  • ๊ธฐ๋ณธ๊ฐ’ 0

3. flex-flow

Shorthand property for flex-direction and flex-wrap

  • ๊ธฐ๋ณธ๊ฐ’ row wrap

    image-20200323132416926
  • row-reverse nowrap

    image-20200323132522691
  • column wrap-reverse

    image-20200323132557885
  • column wrap

    image-20200323132931108

4. justify-content

main ์ถ•์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค

  • ๊ธฐ๋ณธ๊ฐ’: flex-start

  • flex-start

  • flex-end

  • center

  • space-around

  • space-between

  • space-evenly

5. align-items

crosss ์ถ•์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค

  • stretch

    : ๊ธฐ๋ณธ๊ฐ’

  • flex-start

    : ์ƒ๋‹จ ์ •๋ ฌ

  • flex-end

    : ํ•˜๋‹จ ์ •๋ ฌ

  • baseline

    : items are aligned such as their baselines

  • center

    : ์ค‘์•™ ์ •๋ ฌ

    image-20200323135424441

6. align-content

Sets the distribution of space between and around content items along a flexbox's cross-axis or a gird's block axis

align-content has no effect when there is onlyl one line of flex items!

  • ๊ธฐ๋ณธ๊ฐ’: stretch

  • flex-start

  • flex-end

  • center

  • space-between

  • space-around

    image-20200323135336671

7. order

item์˜ ์ˆœ์„œ๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค

  • ๊ธฐ๋ณธ๊ฐ’: 0

  • ์Œ์ˆ˜๊ฐ’๋„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ

8. align-self

item์— ์ง์ ‘ align์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Œ

flex๋Š” margin-top: auto๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค!

Wrap-up

  • justify - main ์ถ•

  • align - cross ์ถ•

  • content - ์—ฌ๋Ÿฌ์ถ•

  • items - ํ•œ ์ค„

  • self - ๊ฐœ๋ณ„์š”์†Œ

Last updated

Was this helpful?