Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky footer and content with 100% height

I want a page with sticky footer which's scrollbar does not overlap header, only body. Like I do in this fiddle. But now i want that content (dotted box) has 100% height of body.

html

<div class="navbar navbar-inverse navbar-fixed-top"></div>
<div class="container">
   <div class="content-container">
      <div class="my_content">Full height ??</div>
      <div class="push"></div>
   </div>
   <div class="footer"></div>
</div>

css

html,
    body {
        height: 100%;
        overflow: hidden;
    }

    body {
        padding-top: 50px;
    }

    .container {
        overflow-y: auto;
        overflow-x: hidden;
        height: 100%;
    }

    .content-container {
        padding-right: 15px;
        padding-left: 15px;
        margin-right: auto;
        margin-left: auto;
        position: relative;
        padding-top: 15px;
        padding-bottom: 15px;
        min-height: 100%;
        margin-bottom: -60px;
    }

    .footer {
        position: relative;
        width: 100%;
        background-color: red;
    }

    .footer,
    .push {
        height: 60px;
    }

    .my_content {
        border: 1px dotted;
        width: 100%;
        height: 100%;
        min-height: 200px;
        min-width: 300px;
    }

You can suggest any other template for using sticky footer.

like image 667
user3714967 Avatar asked Mar 11 '15 07:03

user3714967


People also ask

Should I use height 100%?

Setting min-height to 100% on both elements does not allow the body element to fill the page like you might expect. If you check the computed style values in dev tools, the body element has a height of zero. Meanwhile, the HTML element has a height equal to the visible part of the page in the browser.

What does height 100% do CSS?

height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.

How do you keep the footer at the bottom even with dynamic height?

Just add data-position="fixed" to the div tag if you are using jQuery. Hope this helps.


1 Answers

You can set .my_content to 100% of the viewport height minus the height and (vertical) padding of the other elements (i.e. header height, footer height, top and bottom padding on .content-container) on your page like so:

.my_content {
  min-height: calc(100vh - 140px);
}

DEMO

If your header and footer have variable heights, this won't work though.

like image 162
Jayx Avatar answered Oct 02 '22 10:10

Jayx