0

In this code I have a sticky footer and a content section above, but why height:100% doesn't work for content section?

html {
  position: relative;
  min-height: 100%;
}
body {
  margin-bottom: 60px;
  height: 100%;
}
.content {
  background-color: #116655;
  height: 100%;
}
.footer {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 60px;
  background-color: #ffcc44;
}
<div class="content">
  <div>content</div>
</div>

<footer class="footer">
  My footer
</footer>
Stickers
  • 75,527
  • 23
  • 147
  • 186
Fcoder
  • 9,066
  • 17
  • 63
  • 100

2 Answers2

0

You need to set an actual height on the html

html {
 position: relative;
  height: 100%; /* not min-height */
}

JsFiddle Demo

Paulie_D
  • 107,962
  • 13
  • 142
  • 161
  • this doesn't work because my sticky footer overlaps the content. right now footer stays under the content ( if we have much content) – Fcoder May 24 '15 at 21:36
  • 2
    Then perhaps `position:absolute` is not the best choice for you...but that wasn't your question. Try another "stick footer" option, perhaps https://css-tricks.com/snippets/css/sticky-footer/ – Paulie_D May 24 '15 at 21:55
0

Use position: absolute on the content as well, then use top: 0 and bottom: 60px this will make the content take up the remaining space. then use overflow: auto; to allow scrolling the content;

(Demo)

.content {
    position: absolute;
    top: 0;
    bottom: 60px;
    background-color: red;
    overflow: auto;
}