Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Align content to bottom when using flex

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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:

.content-end
{
  display: flex;
  justify-content: start; 
}

the content would start from the end without disturbing the scroll

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading