Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep footer with variable height on bottom [duplicate]

Tags:

css

footer

I need to keep a footer on bottom, but its height is variable so main solutions are not suitable for me...

Examples of what I can't do:

  • http://www.cssstickyfooter.com/
  • http://matthewjamestaylor.com/blog/bottom-footer-demo.htm

Anyone have a solution for flexible footers?

like image 265
diegoiglesias Avatar asked Feb 03 '12 10:02

diegoiglesias


1 Answers

2014 UPDATE: The modern way to solve this layout problem is to use the flexbox CSS model. It's supported by all major browsers and IE11+.


Here's a solution for sticky footer of flexible height using divs with display: table-row:

html, body {
  height: 100%;
  margin: 0;
}
.wrapper {
  display: table;
  height: 100%;
  width: 100%;
  background: yellow;
}
.content {
  display: table-row;
  /* height is dynamic, and will expand... */
  height: 100%;
  /* ...as content is added (won't scroll) */
  background: turquoise;
}
.footer {
  display: table-row;
  background: lightgray;
}
<div class="wrapper">
  <div class="content">
    <h2>Content</h2>
  </div>
  <div class="footer">
    <h3>Sticky footer</h3>
    <p>Footer of variable height</p>
  </div>
</div>

What needs to be noted is that CSS was designed to layout documents, not web application screens. The CSS display: table properties are very valid though, and are supported in all major browsers. This is not the same as using structural tables for layout.

like image 53
Dan Dascalescu Avatar answered Sep 17 '22 17:09

Dan Dascalescu