0

I am trying to use flexbox to have fixed height container ( two ) to be stuck to the bottom of the page and then have the other container take up the available space (flex-grow) . This is not giving me the desired effect so I'm not sure what I'm missing

<div class="container"> 
  
  <div class="one">One</div>
  
  <div class="two">Two</div>
  
</div> 


.container {
   height: 100%;
   display: flex;
   flex-direction: column;
   background: black;
}
.one { 
   flex-grow: 1;
   background: green
}
.two {
    height: 90px;
    background:pink;
}

3 Answers3

1

Your block is limited to the place it occupies. You have to use the entire viewport in this case. Add this in your CSS :

html, body {
  height: 100%;
}
Christophe
  • 366
  • 3
  • 3
1

The main thing that would help is height:100vh. Apart from that, to avoid scrollbar, you'll need to remove default margin and padding from html & body.

The vh unit is pretty convenient when you want the container tag to fill the available screen space without introducing vertical scrollbar.

        html,
        body {
          margin: 0;
          padding: 0;
        }
        .container {
          height: 100vh;
          display: flex;
          flex-direction: column;
          background: black;
        }
        .one {
          flex-grow: 1;
          background: green;
        }
        .two {
          height: 90px;
          background: pink;
        }
        <html>

        <body>
          <div class="container">
            <div class="one">One</div>
            <div class="two">Two</div>
          </div>
        </body>

        </html>
R J
  • 495
  • 5
  • 12
0

Height (%) is used to define a height relative to parent's height. It depends on parent element height so you also need to set height:100% to html/body.

body, html{
  height: 100%;
}

.container {
   height: 100%;
   display: flex;
   flex-direction: column;
   background: black;
}
.one { 
   flex-grow: 1;
   background: green
}
.two {
    height: 90px;
    background:pink;
}
<div class="container"> 
  
  <div class="one">One</div>
  
  <div class="two">Two</div>
  
</div> 
NcXNaV
  • 1,657
  • 4
  • 14
  • 23