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

后端 未结 6 655
别跟我提以往
别跟我提以往 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:48

    A starting point:

    body {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      overflow: auto;
    }
    

    (or add a container div with an ID, etc if you have issues with some browsers.)

    EDIT: Adding full code example below:

    
        
        
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    CSS:

    * {
      font-size: 2em
    }
    
    aside {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 200px;
        background-color: pink;
    }
    
    #main {
        position: absolute;
        top: 0;
        left: 200px;
        right: 0;
        bottom: 0;
        overflow: auto;
        background-color: red;
    }
    

提交回复
热议问题