You were almost there. Just a stone's throw from the hotel:
- Make the
#body container flex. - Give
.wrapper2 full height with flex: 1 .
(I also got rid of percentage heights, you don't need them.)
body { margin: 0; } #wrapper { display: flex; flex-direction: column; min-height: 100vh; } #header { background: yellow; height: 100px; } #body { flex: 1; border: 1px solid orange; display: flex; flex-direction: column; } #wrapper2 { display: flex; flex-direction: column; flex: 1; } #body2 { border: 1px solid purple; flex: 1; } #footer2 { background: red; } #footer { background: lime; }
<div id="wrapper"> <div id="body"> Bodyof <br>variable <br>height <br> <div id="wrapper2"> <div id="body2">blah</div> <div id="footer2"> blah <br>blah </div> </div> </div> <div id="footer"> Footer <br>of <br>variable <br>height <br> </div> </div>
After the adjustments are made, you can align the inner (red) footer to the lower level:
flex: 1 on #body2 , this is what you have, ormargin-bottom: auto on #body2 ormargin-top: auto on #footer2 orjustify-content: space-between on container ( #wrapper2 )
source share