Why is the footer sticking out below?
The problem is the fixed height that you set for the main container with a flexible display. If you just delete this height or set it to auto. Since #main is not a flexible element , it retains its entire height, but since its contents are flexible, they collapse to the beginning.
But then the content filler does not occupy the full space?
He does not occupy any space, because now there is no height. You can simply set a minimum height in the content filler or just let it grow dynamically. Once you hide all the footers matching the top, since the main container no longer has a fixed height.
var button = document.getElementById('child-switcher'); var child = document.getElementById('content-filler'); button.onclick = function() { if (child.style.display === 'none') { child.style.display = null; } else { child.style.display = 'none'; } }
#main { height: auto; display: flex; flex-direction: column; } #footer { background-color: green; } #content { flex: 1; display: flex; flex-direction: column; } #some-nested-content { display: flex; flex: 1; flex-direction: column; } #content-filler { flex: 1; min-height:200px; background-color: red; } #content-header, #content-footer { background-color: yellow; }
<div id="main"> <button id="child-switcher"> Hide/show the child </button> <div id="content"> <div id="some-nested-content"> <div id="content-header"> CONTENT_HEADER </div> <div id="content-filler"> FILLING REMAINING HEIGHT </div> <div id="content-footer"> CONTENT_FOOTER </div> </div> </div> <div id="footer">FOOTER</div> </div>
user7207170
source share