How to make flexbox children 100% height of their parent using CSS?

CSS Flexbox is an awesome tool to create website layouts. Making a flex-box child 100% height of their parent can be done in two ways. It is little tricky because, certainly it will display an error.
For example, the child may flow out of the parent boundary or it may not get upto 100% height that you will see in your browser output.

Example 1: This example makes a child flex-box of height 100% using CSS.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
   <head>
      <title>
          Make flex-box child height 100%
      </title>
        
      <style>
         * {
             padding: 0;
             margin: 0;
         }
         .container {
             width: 100vw;
             height: 50vh;
             background-color: green;
             display: flex;
             justify-content: center;
             align-items: center;
         }
         .child-div {
             height: 100%;
             background-color: red;
             margin: 0 20px;
         }
      </style>
   </head>
     
   <body>
      <div class="container">
         <div class="child-div">
            One
         </div>
         <div class="child-div">
            Two
         </div>
         <div class="child-div">
            Three
         </div>
         <div class="child-div">
            Four
         </div>
         <div class="child-div">
            Five
         </div>
      </div>
   </body>
</html>

chevron_right


Output:

Example 2: The second way to achieve this by using align-items property in the parent div to ‘strech’. It makes every .child-div 100% height of it’s parent height.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
   <head>
      <title>
          Make flex-box child height 100%
      </title>
        
      <style>
         *{
             padding: 0;
             margin: 0;
         }
         .container{
             width: 100vw;
             height: 50vh;
             background-color: green;
             display: flex;
             justify-content: center;
             align-items: stretch;
         }
         .child-div{
             background-color: red;
             margin: 0 20px;
         }
      </style>
   </head>
     
   <body>
      <div class="container">
         <div class="child-div">
            One
         </div>
         <div class="child-div">
            Two
         </div>
         <div class="child-div">
            Three
         </div>
         <div class="child-div">
            Four
         </div>
         <div class="child-div">
            Five
         </div>
      </div>
   </body>
</html>

chevron_right


Output:

Example 3: This example makes width of child to 100% of there parent.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
   <head>
      <title>
          Make flex-box child width 100%
      </title>
        
      <style>
         * {
             padding: 0;
             margin: 0;
         }
         .container {
             width: 100vw;
             height: 50vh;
             background-color: green;
             display: flex;
             flex-direction: column;
             justify-content: center;
             align-items: stretch;
         }
         .child-div {
             background-color: red;
             margin: 20px 0;
             padding: 5px;
         }
      </style>
   </head>
     
   <body>
      <div class="container">
         <div class="child-div">
            One
         </div>
         <div class="child-div">
            Two
         </div>
         <div class="child-div">
            Three
         </div>
         <div class="child-div">
            Four
         </div>
         <div class="child-div">
            Five
         </div>
      </div>
   </body>
</html>

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.