When working with dynamic content that includes a footer, a problem sometimes occurs where the content on a page is not enough to fill it. The footer, rather than staying at the bottom of the page where we would want it to stay, rises up and leaves a blank space beneath it.
html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app">
<div class="container">
<header></header>
<main></main>
</div>
<footer>
CopyRight
</footer>
</div>
</body>
</html>
css
html, body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
footer {
margin-top: auto;
flex-grow: 1;
}
My code is in the vertical center of the page.