Вы можете легко сделать это с помощью сетки CSS:
body {
display:grid;
grid-template-rows: auto 1fr auto;
justify-content:center;
grid-gap:4px;
min-height: 100vh;
margin:0;
}
header,
main,
footer {
border: thin solid #ccc;
}
<header>
Header
</header>
<main>
Main
</main>
<footer>
Footer
</footer>
Или рассмотрите возможность поведения усадки inline-flex
:
body {
text-align:center;
margin:0;
}
.container {
display: inline-flex;
flex-direction: column;
min-height: 100vh;
text-align:left;
}
main {
flex: 1;
}
header,
main,
footer {
border: thin solid #ccc;
margin: 4px;
}
<div class="container">
<header>
Header
</header>
<main>
Main
</main>
<footer>
Footer
</footer>
</div>