I am trying to achieve a layout that stretches to fill the screen, but then scrolls when the content is larger than the available pane.
I have a basic flexbox
approach based on this answer, and it does a good job filling up the screen, but overflowing content causes the whole screen to scroll rather than just its own container.
If I change .outer
height to a literal value like 200px
then I get the scrolling behavior that I want, but the bottom content pane no longer fills up the screen.
I have tried using display: table
and related CSS rather than flexbox, but ended up with the same result.
I have also considered using calc
on the height of the content pane - something like
height: calc(100% - 60px);
but I want the header to be able to grow with its content, so I don't have a hard value for its height for the calculation.
I am looking for a pure CSS solution here rather than window sizing with Javascript of some flavor.
html,
body {
height: 100%;
margin: 0
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.box .row {
border: 1px dotted grey;
flex: 1 1 auto;
}
.box .row.header {
background: aliceblue;
}
.box .row.content {
background: pink;
}
.box .row.content .title {
height: 40px;
background: yellow;
}
.outer {
height: -webkit-calc(100% - 40px);
height: -moz-calc(100% - 40px);
height: -o-calc(100% - 40px);
height: calc(100% - 40px);
overflow-y: auto;
}
.inner {
height: 100%;
}
.text {
height: 100px;
margin-top: 10px;
border: 1px solid gold;
}
<div class="box">
<div class="row header">
<p><b>header</b>
<br />
<br />(sized to content)</p>
</div>
<div class="row content">
<div class="title">
<b>content</b>
(fills remaining space)
</div>
<div class="outer">
<div class="inner">
<div class="text">Bacon ipsum dolor amet tongue corned beef landjaeger sausage beef meatball, kielbasa pastrami turkey boudin hamburger ham hock chuck tail pork. Shankle tail cupim ribeye.</div>
<div class="text">Bacon ipsum dolor amet tongue corned beef landjaeger sausage beef meatball, kielbasa pastrami turkey boudin hamburger ham hock chuck tail pork. Shankle tail cupim ribeye.</div>
<div class="text">Bacon ipsum dolor amet tongue corned beef landjaeger sausage beef meatball, kielbasa pastrami turkey boudin hamburger ham hock chuck tail pork. Shankle tail cupim ribeye.</div>
<div class="text">Bacon ipsum dolor amet tongue corned beef landjaeger sausage beef meatball, kielbasa pastrami turkey boudin hamburger ham hock chuck tail pork. Shankle tail cupim ribeye.</div>
<div class="text">Bacon ipsum dolor amet tongue corned beef landjaeger sausage beef meatball, kielbasa pastrami turkey boudin hamburger ham hock chuck tail pork. Shankle tail cupim ribeye.</div>
<div class="text">Bacon ipsum dolor amet tongue corned beef landjaeger sausage beef meatball, kielbasa pastrami turkey boudin hamburger ham hock chuck tail pork. Shankle tail cupim ribeye.</div>
<div class="text">Bacon ipsum dolor amet tongue corned beef landjaeger sausage beef meatball, kielbasa pastrami turkey boudin hamburger ham hock chuck tail pork. Shankle tail cupim ribeye.</div>
</div><!-- inner -->
</div><!-- outer -->
</div>
</div>