skip to Main Content

I have this basic layout with a static header and footer, pushed to the top and bottom respectively. The content section in the middle fills the space, and there’s a scrollbar for this section in case the content is too large for it to fit.

<div id="app">
  <div id="header">
    Header
  </div>

  <div id="middle">
    Middle content
  </div>

  <div id="footer">
    Footer
  </div>
</div>
html,
body {
  height: 100%;
  overflow: hidden;
  margin: 0;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#header {
  height: 60px;
  background-color: blue;
}

#footer {
  height: 60px;
  background-color: red;
}

#middle {
  flex: 1;
  overflow-y: scroll;
  align-items: flex-end;
}

jsfiddle here.

I want the content of this middle section to start from the bottom, and not the top, while keeping the overflow scrollbars in case the content is too big, but I can’t seem to figure out how.

I’ve tried setting margins to 0 and read about flex-direction, but none of those seem to work.

2

Answers


  1. You can try the following :

      <div id="header">
        Header
      </div>
    
      <div id="middle" class="content-end">
        Middle content
      </div>
    
      <div id="footer">
        Footer
      </div>
    </div> 
    

    Please add this in your css:

    html,
    body {
      height: 100%;
      overflow: hidden;
      margin: 0;
    }
    
    #app {
      display: flex;
      flex-direction: column;
      height: 100%;
      overflow: hidden;
    }
    
    #header {
      height: 60px;
      background-color: blue;
    }
    
    #footer {
      height: 60px;
      background-color: red;
    }
    
    #middle {
      flex: 1;
      overflow-y: scroll;
     
      display: flex;
    }
    
    .content-end
    {
      display: flex;
      justify-content: start; 
    
    
    }
    
    

    scroll

    Login or Signup to reply.
  2. Please update your css there are not major changes. Use proper HTML tags in #middle

    * {
      margin: 0; padding: 0;
      box-sizing: border-box; 
    }
    html,
    body {
      height: 100%;
      overflow: hidden; margin: 0;
    }
    #app {
      display: flex;
      flex-direction: column;
      height: 100%;
      overflow: hidden;
    }
    #header {
      height: 60px;
      background-color: blue;
    }
    #footer {
      height: 60px;
      background-color: red;
    }
    #middle {
      flex: 1;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      padding-top: calc(100vh - 180px);
    }
    #middle * {
      margin-bottom: 10px;
    }
    

    With this approach the first child in #middle will start from the bottom and rest will follow it. you can play around with this padding-top.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search