ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • CSS Flex Container
    웹개발/HTML&CSS 2022. 11. 25. 17:53

    Flex container

    The flex container becomes flexible by setting the display property to flex

    .flex-container {
      display: flex;
    }

    The flex container properties are:

     

    Flex Items (Child Elements)

    The direct child elements of a flex container automatically becomes flexible (flex) items.

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    .flex-container {
      display: flex;
      background-color: #f1f1f1;
    }
    
    .flex-container > div {
      background-color: DodgerBlue;
      color: white;
      width: 100px;
      margin: 10px;
      text-align: center;
      line-height: 75px;
      font-size: 30px;
    }
    </style>
    </head>
    <body>
    
    <h1>Flexible Items</h1>
    
    <div class="flex-container">
      <div>1</div>
      <div>2</div>
      <div>3</div> 
      <div>4</div>
    </div>
    
    <p>All direct children of a flexible container becomes flexible items.</p>
    
    </body>
    </html>

    The flex item properties are:


     

    1. The flex-direction Property

    column; row;

    .flex-container {
      display: flex;
      flex-direction: column;
    }

    2.The justify-content Property (horizontal)

    center; space-around; space-betwwen

    .flex-container {
      display: flex;
      justify-content: center;
    }

    3. The align-items Property (vertical)

    stretch(default); baseline;

    .flex-container {
      display: flex;
      height: 200px;
      align-items: center;
    }

     


    4. flex-grow Property

    <div class="flex-container">
      <div style="flex-grow: 1">1</div>
      <div style="flex-grow: 1">2</div>
      <div style="flex-grow: 8">3</div>
    </div>

     

     

     

Designed by Tistory.