javascript – Unable to correctly pin this footer to the bottom of the viewport

html - Animation after toggling doesn't apply the second style

I am trying to auto scroll the content, which is working. However, when I try to pin the footer to the bottom of the viewport, the content scrolls past the footer and the footer scrolls with the content.

If I remove the CSS for the footer element, the footer starts at the top, the content pushes it to the bottom, and the content auto-scrolls on top of the footer as expected.

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
        height: 100%;
        display: flex;
        flex-direction: column;
        overflow-y: scroll;
    footer {
        position: absolute !important;
        bottom: 0 !important;
        width: 100%;

    <div class="container" id="cont">
        <header class="sticky"><h1>Header</h1></header>
        <div id="content"></div>
        <footer class="sticky"><h3>Footer</h3></footer>
    window.addEventListener('DOMContentLoaded', (event) => {

        history.scrollRestoration = "manual"
        window.scrollTo(0, document.body.scrollHeight)


            var content = document.getElementById("content")
            var textnode = document.createElement("div")

            textnode.innerText = Math.random()

            window.scrollTo(0, document.body.scrollHeight)

        }, 500)



Source link

Leave a reply

Please enter your comment!
Please enter your name here