I need to have a vertical parent-height div which contains smaller divs. In case there's extra space, all but the last divs should be placed on top, and the latest div should be placed at the bottom. I've implemented it with Bootstrap and flex.
Now I thought that it would be nice if, when possible, the bottom div will be at the bottom of the viewport instead of at the bottom of the containing div. I've implemented it with position: sticky
, and it works on Chrome but not in Firefox (both should support position: sticky
).
My code:
<div id="container" class="d-flex flex-column">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="d-flex flex-column last">
<div class="flex-item mt-auto last-inner">3</div>
</div>
</div>
CSS:
#container {
height: 1000px;
}
#container .last {
flex: 1;
}
#container .last-inner {
position: sticky;
bottom: 0;
}