-2

I know, this kind of questions has been asked a lot, but somehow the correct answer is always eluding me...

Ok, I've got two things I want:

  • A footer that's always on the bottom of the page, no matter if the content has less height than the available screen or more.
  • The content above the footer should fill the rest of the screen - or use more space, if needed

The first part is quite easy, for example, here, with something like this...

.footer {
  position: absolute;
  bottom: 0;
  left: 0;
}

No problem there. But how can I get the content above the .footer element to fill the remaining space? height=100%; obviously doesn't work;

Anyone got an idea how to realize a layout with...

  • A fixed header
  • A footer at the bottom of the screen (or below, if the content needs more height than that)
  • A content that fills the available screen or uses more, if needed

(The reason is that in the end, I want a grid with flexible height that fills the screen in the content)

Florian Schaetz
  • 10,454
  • 5
  • 32
  • 58

1 Answers1

0

header {
    width: 100%;
    position: fixed;
    background-color: #9f0d0d;
    color: #f5f5f5;
    border-bottom: 1px solid #ddd;
    min-height: 5%;
}

    header :first-child {
        vertical-align: middle;
        margin-top: auto;
        margin-bottom: auto;
    }

article {
    top: 55px;
    width: 100%;
    height: 90%;
    position: fixed;
}

footer {
    top: 95%;
    min-height: 5%;
    width: 100%;
    position: fixed;
    padding: 10px 15px;
    background-color: #9f0d0d;
    color: #f5f5f5;
    border-top: 1px solid #ddd;
}
<div>
  <header>HEADER</header>
  <article>CONTENT</article>
  <footer>FOOTER</footer>
</div>
 

Feel Free to play with this code block.

jmag
  • 796
  • 1
  • 8
  • 17