How to stick a footer to bottom in css?

后端 未结 12 494
别跟我提以往
别跟我提以往 2020-12-01 05:09

I am having the classic problem for the positioning of a Footer on the bottom of the browser. I\'ve tried methods including http://ryanfait.com/resources/footer-stick-to-bot

12条回答
  •  温柔的废话
    2020-12-01 05:39

    For modern browser, you can use flex layout to ensure the footer stays at the bottom no matter the content length (and the bottom won't hide the content if it is too long)

    HTML Layout:

    My header
    My Main page content
    My footer

    CSS:

    html, body {
      min-height: 100vh;
      width: 100%;
      padding: 0;
      margin: 0;
    }
    
    .layout-wrapper {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }
    
    .layout-wrapper > .page-content {
      background: cornflowerblue;
      color: white;
      padding: 20px;
    }
    
    .layout-wrapper > header, .layout-wrapper > footer {
      background: #C0C0C0;
      padding: 20px 0;
    }
    

    Demo: https://codepen.io/datvm/pen/vPWXOQ

提交回复
热议问题