Thanks to a good answer here, and a superb one here, I've got most of the layout I'm aiming for. Sticky, fixed height header and footer, body in the middle - centered and at a fixed aspect ratio.
The only thing not working is that the body pushes the footer off the bottom, so that it's no longer sticky. (run snippet, scroll down to see the not-sticky-anymore footer).
The only way I've been able to affect this is by limiting the height of the #parent
div, for example, to 80vh
. This ends up leaving space above the footer depending on the vh.
Is there a way to do just this layout below, except keep the footer on the page?
I found a pertinent similar question here on SO, but alas, unanswered.
* { margin: 0; box-sizing: border-box; }
body {
display: flex;
flex-direction: column;
min-height: 100vh;
margin: 0;
}
header {
background-color: #cffac7;
height: 50px;
}
main {
background-color: #55086d;
}
footer {
background-color: #fceec7;
height: 50px;
margin-top: auto;
}
#parent {
width: 100vw;
height: 100vh;
background-color: red;
display: flex;
justify-content: center;
align-items: center;
}
.ar-box {
max-width: 100%;
max-height: 100%;
background-color: #0bf;
aspect-ratio: 3/5;
}
.ar-box:after {
display: block;
content: "";
min-width: 100vw;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./styles.css">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
</head>
<body>
<header>header :-)</header>
<main>
<div id="parent">
<div class="ar-box">body :-)</div>
</div>
</main>
<footer>footer :-(</footer>
</body>
</html>