How to push a footer to the bottom of page when content is short or missing?

前端 未结 13 1302
囚心锁ツ
囚心锁ツ 2020-12-04 16:55

I have a page with an outer div that wraps a header, content and footer div. I want the footer div to hug the bottom of the browser, even when the content div is not tall e

13条回答
  •  一整个雨季
    2020-12-04 17:13

    What I wanted was to have the footer be at the bottom of browser view ONLY IF the content was not long enough to fill up the browser window (non-sticky).

    I was able to achieve by using the CSS function calc(). Which is supported by all modern browsers. You could use like:

    CONTENT

    the css:

    .container
    {
        min-height: 70%;
        min-height: -webkit-calc(100% - 186px);
        min-height: -moz-calc(100% - 186px);
        min-height: calc(100% - 186px);
    }
    

    Change 186 to the size of your footer.

提交回复
热议问题