How to stick footer to bottom (not fixed) even with scrolling

前端 未结 9 1048
温柔的废话
温柔的废话 2021-02-03 20:53

I\'m learning web development and I simply can\'t figure out what I\'m doing wrong on this. I want the footer of this page to stick to the bottom, below all content, but not fix

9条回答
  •  独厮守ぢ
    2021-02-03 21:02

    The accepted answer might be a bit outdated since we have Flexbox now. Give the container a min-height: 100vh and the footer a margin-top: auto so you don't have to deal with absolute positioning and fixed heights.

    body {
        margin: 0;
    }
    
    .container {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
    }
    
    .header {
        background-color: #FFCCCC;
    }
    
    .content {
        background-color: #CCFFCC;
    }
    
    .footer {
        background-color: #CCCCFF;
        margin-top: auto;
    }
    header
    content

提交回复
热议问题