Making html and body stretch to 100% height and more if the page scrolls

后端 未结 6 644
别跟我提以往
别跟我提以往 2020-12-18 22:08

I want to make my and tags be the entire height of the viewport if the page isn\'t tall enough to warrant scrolling, or t

6条回答
  •  一向
    一向 (楼主)
    2020-12-18 22:31

    It sounds like your goal is for the body to

    • always cover the screen (with minimal or no content)
    • be able to stretch (if there is a ton of content)

    if that's the case the following snippet should help

    /* this looks like it should work
    
           html, body{
             min-height: 100%;
           }
    
        but this ↓ does the trick */
    
    html, body{
      padding: 0;
      margin: 0;
    }
    html{
      height: 100%;
    }
    body{
      min-height: 100%;
    }
    

提交回复
热议问题