CSS to make HTML page footer stay at bottom of the page with a minimum height, but not overlap the page

前端 未结 29 2522
悲哀的现实
悲哀的现实 2020-11-21 23:48

I have the following page (deadlink: http://www.workingstorage.com/Sample.htm ) that has a footer which I can\'t make sit at the bottom of the page.

I wa

29条回答
  •  故里飘歌
    2020-11-22 00:24

    A very simple flex solution that does not assume fixed heights or changing position of elements.

    HTML

    CSS

    .container {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
    }
    
    main {
      flex: 1;
    }
    

    Browser Support

    All major browsers, except IE11 and below.

    Make sure to use Autoprefixer for appropriate prefixes.

    .container {
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-orient: vertical;
      -webkit-box-direction: normal;
      -ms-flex-direction: column;
      flex-direction: column;
      min-height: 100vh;
    }
    
    main {
      -webkit-box-flex: 1;
      -ms-flex: 1;
      flex: 1;
    }
    
    /////////////////////////////////////////////
    
    body,
    html {
        margin: 0;
        padding: 0;
    }
    
    header,
    main,
    footer {
      margin: 0;
      display: block;
    }
    
    header,
    footer {
      min-height: 80px; 
    }
    
    header {
      background-color: #ccc;
    }
    
    main {
      background-color: #f4f4f4;
    }
    
    footer {
      background-color: orange;
    }

提交回复
热议问题