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

前端 未结 29 2521
悲哀的现实
悲哀的现实 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:11

    I just answered as similar question in here:

    Position footer at bottom of page having fixed header

    I'm pretty new at web development, and I know this has been answered already, but this is the easiest way I found to solve it and I think is somehow different. I wanted something flexible because the footer of my web app has a dynamic height, I ended up using FlexBox and a spacer.

    1. Start by setting the height for your html and body
    html, body {
        height: 100%;
        display: flex;
        flex-direction: column;
        margin: 0px;
    }
    

    I'm assuming a column behavior for our app, in the case you need to add a header, hero or any content vertically aligned.

    1. Create the spacer class
    .spacer {
        flex: 1; 
    }
    
    1. So later on your HTML could be something like
    
      
        
    Header
    Some content...
    Footer

    You can play with it here https://codepen.io/anon/pen/xmGZQL

提交回复
热议问题