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

CSS flex div get's larger as max-height

i got following HTML structure:

Demo here

<div id="wrapper">

  <div id="header">
    <i>Header</i>
  </div>
  
  <div id="content">
    <i>Content</i>
  </div>
  
  <div id="footer">
      <i>Footer</i>
  </div>

</div>
#wrapper{
  margin: 0;
  height: 100vh;
  max-height: 100vh;
  /* overflow: hidden; */
display: flex;
  flex-direction: column;
}

#header{
  background: blue;
  height: 3rem;
}

#content{
  background: red;
  flex-grow: 1;
}

#footer{
  background: green;
  height: 3rem;
}

My problem is that when the div of the content gets too large, the wrapper ignores his max-height and gets a scrollbar. What i want is that the content div instead gets the scrollbar and the wrapper holds it’s height.

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

Demo of content to large

>Solution :

You have to make the wrapper overflow: hidden so scroll-bar is disabled for that div.
Next, You can add the overflow: auto to content to make it scrollable if content goes outside.

#wrapper{
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: red;
  overflow: hidden;
}
#content{
  flex-grow: 1;
  overflow: auto;
}
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