I have a problem where the content of a div will overflow the parent even with max-height set to 100%. I know that this problem could be simply solved by setting an explicit height; however, this can only be done through JavaScript which is a rather ugly solution. I'd like to continue using my flexbox system to arrange the page, but I would like only the div with the content to be scroll-able. Currently, I'm not able to do this because I can't set an explicit size on the parent. Here is an example of what I am facing:
html,
body {
width: 100%;
height: 100%;
background: lightblue;
box-sizing: border-box;
display: flex;
margin: 0;
}
.hozwrapper {
width: 100%;
height: 100%;
display: flex;
}
.sec1 {
background: red;
width: 50px;
height: 100%;
}
.sec2 {
background: lime;
flex-grow: 1;
}
.vertwrap {
height: 100%;
display: flex;
flex-direction: column;
}
.topbox {
height: 30px;
background: pink;
}
.cbox1 {
background: orange;
height: 100%;
flex-grow: 1;
overflow-y: scroll;
}
.cbox2 {
background: blue;
}
<body>
<div class="hozwrapper">
<div class="sec1">
first
</div>
<div class="sec2">
<div class="vertwrap">
<div class="topbox">
Navbar
</div>
<div class="hozwrapper">
<div class="cbox1">
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
this is content<br>
</div>
<div class="cbox2">
sidebar
</div>
</div>
</div>
</div>
</div>
</body>
If you look at this snippet, when the content overflows it expands the body. This is the behavior I'd like to change.