I have a site with dynamic content on which I want one section to fill the remaining height of the screen, but the caveat is that if the content in that section would cause the height of the page to exceed the viewport height, I want to stop the height of the section it at the bottom edge of the screen and add a vertical scrollbar for just that section.
I'm using CSS Flexbox. Here's a very simplified version of the markup and CSS:
body, div, h1, h2, html, p {
margin: 0;
padding: 0;
}
body,
html {
height: 100%;
}
.siteContainer {
background: gold;
display: flex;
flex-direction: column;
min-height: 100%;
}
.contentContainer {
background: lightblue;
display: flex;
flex: 1;
flex-direction: column;
}
.subcontentContainer {
background: pink;
flex: 1;
overflow-y: scroll;
}
<div class="siteContainer">
<h1>Header</h1>
<div class="contentContainer">
<h2>Subheader</h2>
<div class="subcontentContainer">
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
<p>Some text here.</p>
</div>
</div>
</div>
Assuming your screen has some height to it, you should see the pink section take up most of the screen and the text should not be going vertically off the screen.
However, if you were to copy and paste the <p>Some text here.</p>
part a bunch more times so that the text goes off the screen, then you will see that the viewport scrollbar is enabled.
Instead of the viewport scrollbar though, I want to stop the content at the bottom edge of the screen (presumably with overflow-y
or something like that) and add a scrollbar to just the pink section and not have a scrollbar for the viewport.
Is this possible with only CSS, and if so, how? Thank you.