简体   繁体   中英

Why height 100% doesn't work for the content?

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> 

You need to set an actual height on the html

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

JsFiddle Demo

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM