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

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

    Yet, another really simple solution is this one:

    html, body {
        height: 100%;
        width: 100%;
        margin: 0;
        display: table;
    }
    
    footer {
        background-color: grey;
        display: table-row;
        height: 0;
    }
    

    jsFiddle

    The trick is to use a display:table for the whole document and display:table-row with height:0 for the footer.

    Since the footer is the only body child that has a display as table-row, it is rendered at the bottom of the page.

提交回复
热议问题