I have three different divs in my setup:
- The grey div acts as the outer div and sets the height
- The green div is responsible for scrolling through the content inside of
- The red div, which contains the actual content
Below is a simplified code sample that illustrates the issue I am facing.
.outer {
max-height: 500px;
background-color: gray;
}
.inner {
overflow-y: scroll;
height: 100%;
background-color: green;
margin-right: 100px;
}
.content {
height: 2000px;
background-color: red;
margin-right: 100px;
}
<html>
<body style="overflow-y: hidden">
<div class="outer">
<div class="inner">
<div class="content"></div>
</div>
</div>
</body>
</html>
Even though the grey div has a maximum height of 500px
, the green div takes on the height of the red div and fails to scroll its content.
If I set height: 100%
to the grey div, the scrolling works correctly for content larger than the height of the grey div. However, when the content (red div) is smaller, I want the green div to only be the height of its content.