0

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.

Mahmoud Khosravi
  • 356
  • 4
  • 9
  • 17

1 Answers1

-1

Try absolute positioning:

footer {
   position: absolute;
   bottom: 0;
}

This way the footer will stick to the very bottom of the page.

Daweed
  • 1,419
  • 1
  • 9
  • 24