1.  flex-direction

๐Ÿฐ  flex-direction์ด row์ธ ๊ฒฝ์šฐ ์ปจํ…Œ์ด๋„ˆ์˜ ์ž์‹ ์š”์†Œ์— ๋„“์ด๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ๋‚ด๋ถ€ ์ปจํ…์ธ ์— ๋”ฐ๋ผ ๋„“์ด๊ฐ€ ์ •ํ•ด์ง
         โ–ถ๏ธ  inline-block ์†์„ฑ๊ณผ ์œ ์‚ฌ
      

๐Ÿฐ  flex-direction์ด column์ธ ๊ฒฝ์šฐ ๋„“์ด๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ์ž๋™์œผ๋กœ ๋„“์ด๊ฐ€ 100%๋กœ ์ •ํ•ด์ง.
        โ–ถ๏ธ  block ์†์„ฑ๊ณผ ์œ ์‚ฌ

    <style>
        #container {
            margin-top: 10px;
            border: 3px solid #af94de;
            display: flex;
            flex-direction: column | row;
        }

        .item {
            padding: 10px;
            margin: 10px;
            background: #fcfc9e;
            color: #525d73;
        }
    </style>
</head>
<body>
    <div id="container">
        <div class="item">Item 1</div>
        <div class="item">Item 2</div>
        <div class="item">Item 3</div>
        <div class="item">Item 4</div>
        <div class="item">Item 5</div>
        <div class="item">Item 6</div>
        <div class="item">Item 7</div>
        <div class="item">Item 8</div>
    </div>
</body>

 

flex-direction: row

 

flex-direction:column

 

 


 

2. flex-wrap

๐Ÿฐ  flex-direction: column ์ผ ๋•Œ ์†์„ฑ ์ ์šฉ ์•ˆ ๋จ

     /* ์œ„ ์˜ˆ์ œ ์Šคํƒ€์ผ๊ณผ ๋˜‘๊ฐ™์ด ์ ์šฉํ•˜๊ณ  flex-wrap ์†์„ฑ๋งŒ ์ถ”๊ฐ€ */
     #container {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap | wrap-reverse;
        }

    </style>
</head>
<body>
    <div id="container">
        <div class="item">Item 1</div>
        <div class="item">Item 2</div>
        <div class="item">Item 3</div>
        <div class="item">Item 4</div>
        <div class="item">Item 5</div>
        <div class="item">Item 6</div>
        <div class="item">Item 7</div>
        <div class="item">Item 8</div>
        <div class="item">Item 9</div>
        <div class="item">Item 10</div>
        <div class="item">Item 11</div>
        <div class="item">Item 12</div>
    </div>

</body>

 

์ฃผ์ถ•์ด row์ธ ๊ฒฝ์šฐ, flex-wrap ์†์„ฑ์˜ wrap๊ณผ wrap-reverse๋ฅผ ์ ์šฉํ–ˆ์„ ๋•Œ
์ฃผ์ถ•์ด column์ธ ๊ฒฝ์šฐ ์ ์šฉ ์•ˆ๋จ

 


 

3.  justify-content

๐Ÿฐ  flex-direction: column ์ผ ๋•Œ ์†์„ฑ ์ ์šฉ ์•ˆ ๋จ

flex-start : ์ค„์˜ ์‹œ์ž‘ ์ง€์ ์— ๋ฐฐ์น˜. ์™ผ์ชฝ ๋งž์ถค. ๊ธฐ๋ณธ ๊ฐ’
flex-end : ์ค„์˜ ๋ ์ง€์ ์— ๋ฐฐ์น˜. ์˜ค๋ฅธ์ชฝ ๋งž์ถค.
center : ๊ฐ€์šด๋ฐ ๋งž์ถค
space-between : ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ ๋์— ์žˆ๋Š” ์š”์†Œ๋ฅผ ๋์— ๋ถ™์ด๊ณ , ๋‚จ์€ ๋ถ€๋ถ„๋“ค์€ ๊ท ๋“ฑํ•œ ๊ณต๊ฐ„์„ ํ˜•์„ฑํ•œ ์ƒํƒœ๋กœ ๋ฐฐ์น˜.
space-around : ํ•ญ๋ชฉ๋“ค ๊ฐ„์— ๋™์ผํ•œ ๊ฐ„๊ฒฉ

space-evenly : ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ ๋์— ์žˆ๋Š” ๊ณต๊ฐ„๋„ ํฌํ•จํ•ด์„œ ๊ท ๋“ฑํ•œ ์—ฌ๋ฐฑ์„ ํ˜•์„ฑํ•œ ์ƒํƒœ๋กœ ๋ฐฐ์น˜
<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #container {
            margin-top: 10px;
            border: 3px solid #af94de;
            display: flex;
            justify-content: flex-start | flex-end | center |
                             spac-between | space-around | space-evenly;
        }

        .item {
            padding: 10px;
            background: #fcfc9e;
            color: #525d73;
        }
    </style>
</head>
<body>
    <div id="container">
        <div class="item">Item 1</div>
        <div class="item">Item 2</div>
        <div class="item">Item 3</div>
        <div class="item">Item 4</div>
        <div class="item">Item 5</div>
        <div class="item">Item 6</div>
        <div class="item">Item 7</div>
        <div class="item">Item 8</div>
    </div>

</body>

 

flex-start
flex-end
center
space-between
space-around
space-evenly

 


 

4.  align-itmes

๐Ÿฐ  ์ˆ˜์ง๋ฐฉํ–ฅ ๋งž์ถค. ๋ถ€๋ชจ ์š”์†Œ์— ๋นˆ๊ณต๊ฐ„์ด ์žˆ์œผ๋ฉด ์ž์‹ ์š”์†Œ์— ์ˆ˜์ง ๋ฐฉํ–ฅ์œผ๋กœ ์–ด๋–ป๊ฒŒ ๋งž์ถœ์ง€ ์ง€์ •

 

flex-start       - ๋ถ€๋ชจ ์š”์†Œ์˜ ์œ—๋ถ€๋ถ„์— ๋งž์ถฐ ๋ฐฐ์น˜
flex-end         - ๋ถ€๋ชจ ์š”์†Œ์˜ ์•„๋žซ๋ถ€๋ถ„์— ๋งž์ถฐ ๋ฐฐ์น˜
center             - ์ค‘์•™์— ๋ฐฐ์น˜
stretch            - ๋ถ€๋ชจ ์š”์†Œ์˜ ๋†’์ด ๋˜๋Š” ์ฝ˜ํ…์ธ ์˜ ๊ฐ€์žฅ ๋†’์ด๊ฐ€ ๋†’์€ ์ž์‹ ์š”์†Œ์— ๋งž์ถฐ ๋Š˜์–ด๋‚จ. ์ดˆ๊ธฐ๊ฐ’
baseline          -  ๋ฌธ์ž ๊ธฐ์ค€์„ ์— ๋งž์ถฐ ๋ฐฐ์น˜

 

<head>
    <style>
        #container {
            margin-top: 10px;
            border: 3px solid #af94de;
            
            display: flex;
            align-items: flex-start | flex-end | center | stretch | baseline;
        }

        .item {
            padding: 10px;
            margin: 10px;
            background: #fcfc9e;
            color: #525d73;
        }
        
        .item:nth-child(2) { /* ๋‘๋ฒˆ์งธ ๋ฐ•์Šค๋งŒ ์ง€์ • */
            padding: 20px;
        }
    </style>
</head>
<body>
    <div id="container">
        <div class="item">Item 1</div>
        <div class="item">Item 2</div>
        <div class="item">Item 3</div>
        <div class="item">Item 4</div>
        <div class="item">Item 5</div>
        <div class="item">Item 6</div>
    </div>
</body>

flex-start
flex-end
center
stretch
baseline

 


 

5.  align-content

๐Ÿฐ  ์—ฌ๋Ÿฌ ์ค„์ด ๋  ๋•Œ์˜ ๋งž์ถค. ์ž์‹ ์š”์†Œ๊ฐ€ ์—ฌ๋Ÿฌ ์ค„์ด ๋์„ ๋•Œ์˜ ์ˆ˜์ง ๋ฐฉํ–ฅ ๋งž์ถค์„ ์ง€์ •
๐Ÿฐ  flex-wrap: nowrap ์ด ์ ์šฉ ๋˜์–ด ์žˆ๋‹ค๋ฉด ์ž์‹ ์š”์†Œ๊ฐ€ ํ•œ ์ค„์ด ๋˜๋ฏ€๋กœ align-content ์†์„ฑ ์˜๋ฏธ๊ฐ€ ์—†์Œ

 

flex-start : ๋ถ€๋ชจ ์š”์†Œ์˜ ์œ—๋ถ€๋ถ„์— ๋งž์ถฐ ๋ฐฐ์น˜
flex-end : ๋ถ€๋ชจ ์š”์†Œ์˜ ์•„๋žซ๋ถ€๋ถ„์— ๋งž์ถฐ ๋ฐฐ์น˜
center : ์ค‘์•™์— ๋ฐฐ์น˜
space-between : ์œ„์•„๋ž˜ ๋์— ์žˆ๋Š” ์š”์†Œ๋ฅผ ๋์— ๋ถ™์ด๊ณ , ๋‚จ์€ ๋ถ€๋ถ„๋“ค์€ ๊ท ๋“ฑํ•œ ๊ณต๊ฐ„์„ ํ˜•์„ฑํ•œ ์ƒํƒœ๋กœ ๋ฐฐ์น˜
space-around : ์œ„์•„๋ž˜ ๋์— ์žˆ๋Š” ์—ฌ๋ฐฑ๋„ ํฌํ•จํ•ด์„œ ๊ท ๋“ฑํ•œ ๊ณต๊ฐ„์„ ํ˜•์„ฑํ•œ ์ƒํƒœ๋กœ ๋ฐฐ์น˜
space-evenly : ํ•ญ๋ชฉ๋“ค ๊ฐ„์— ๋™์ผํ•œ ๊ฐ„๊ฒฉ
stretch : ๋ถ€๋ชจ ์š”์†Œ์˜ ๋†’์ด์— ๋งž๊ฒŒ ์ž์‹ ์š”์†Œ์˜ ๋†’์ด๋ฅผ ๋Š˜์—ฌ์„œ ๋ฐฐ์น˜

 

 
        #container {
            width: 400px;
            height: 300px;

            display: flex;
            flex-wrap: wrap;
            align-content: flex-start | flex-end | center | space-between
                           space-around | space-evenly | stretch ;
        }

    </style>
</head>
<body>
    <div id="container">
        <div class="item">Item 1</div>
        <div class="item">Item 2</div>
        <div class="item">Item 3</div>
        <div class="item">Item 4</div>
        <div class="item">Item 5</div>
        <div class="item">Item 6</div>
        <div class="item">Item 7</div>
        <div class="item">Item 8</div>
        <div class="item">Item 9</div>
        <div class="item">Item 10</div>
        <div class="item">Item 11</div>
        <div class="item">Item 12</div>
    </div>

</body>

flex-start / flex-end
center / space-between
space-around / space-evenly

 

stretch

 

 

 

 

[ ๋‚ด์šฉ ์ฐธ๊ณ  : IT ํ•™์› ๊ฐ•์˜ ๋ฐ ์ฑ… 'Do it HTML+CSS+์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์›น ํ‘œ์ค€์˜ ์ •์„' ]

+ Recent posts