I'm trying make some content in my page fill up all the remaining screen size. My page has a header and the content is two divs, both needing to be scrollable. I've tried a few solutions and the best I've come up with is using Flexbox and using CSS calc
to set the height.
But the height of the flexbox is still only the height of the content. Most other answers said to set the body
and html
tags height to 100%. This doesn't work either, and I inspect the page height is not being inherited. So I suspect that may the problem, but I don't know what the answer will be.
I'm also using bootstrap and using a box-sizing
fix for some issues I has with bootstrap, that may also be an issue.
My flexbox CSS:
html,
body {
height: 100%;
/* setting height: 100vh doesn't work either
height: 100vh;
*/
margin: 0
}
body {
background: none repeat scroll 0 0;
padding-top: 105px;
}
/* my header is 102px high and using calc to set the remaining height */
.flex-box {
display: flex;
height: -moz-calc(100% - 102px);
height: -webkit-calc(100% - 102px);
height: calc(100% - 102px);
}
.left {
flex: 1;
order: 1;
overflow: auto;
background:red;
}
.right {
flex: 1;
order: 2;
overflow:auto;
background:green;
}
/* Fix for bootstrap box issues in slickgrid */
*,
*:before,
*:after {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
.container .row *,
.container .row *:before,
.container .row *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
Edit: Adding HTML:
<div class="flex-box">
<div class="left">
<div ui-tree="treeOptions" id="tree-root">
<ol ui-tree-nodes="" ng-model="root.items">
<li data-ng-repeat="item in root.items"
ui-tree-node
data-ng-include="'angularTree.html'"></li>
</ol>
</div>
</div>
<div class="right">
<slickgridjs id="data-grid"></slickgridjs>
</div>
</div>
Edit: Heres a jsfiddle with all the css I'm using, and more complete html.
https://jsfiddle.net/w48567c6/
How can I make the flexbox use the entire remaining screen height?
Thanks everyone for your answers, without them I would not have been able to come up with my solution:
I remembered reading you can mix values in
calc()
, so I changed the flexbox class to:That still gave me some padding at the bottom, so I removed the
height: 100%;
from thehtml
andbody
tags, and it works perfectly.Working fiddle: https://jsfiddle.net/n2nkmgvs/