I'm looking for a solution to fix the max-height of a div related to another div in CSS, if it exceeds it should let use the scrollbar.
I was planned to use flexbox or grid, but I do not success to the result wanted...
The objective is to not specify any height in px but keep something flexible without JS.
// Not looking for JS solution
.parent {
display: flex;
}
.child1 {
background: #eeeeee;
height: 100%
}
.child2 {
overflow: auto;
max-height: 100%;
background: #cccccc
}
<div class="parent">
<div class="child1">
<h2>Child1</h2>
<p>Some content</p>
<p>Some content</p>
<p>Some content</p>
<p>Some content</p>
<p>Some content</p>
</div>
<div class="child2">
<h2>Child2</h2>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
<p>this content height must not exceed the height of "child1"</p>
</div>
</div>