We need to instate a vertical scrollbar for overflow text of a div. The problem is when we set the height to 100% and overflow to auto, it expands beyond its parent container because of another sibling div preceding it. Here is an example:
<style type="text/css">
.container {height: 100px; width: 100px; border: solid;}
.titlebar {height: 2em; background: gray;}
.app-body {height: 100%; overflow: auto; background: lightblue;}
</style>
...
<div class="container">
<div class="titlebar"></div>
<div class="app-body">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec condimentum pretium nisl.</div>
</div>
app-body
set to 100% causes it to have a height of 100px which makes it overflow beyond the bottom of container
by 2em
. We tried not using a height at all for app-body
but that causes it to overflow without the scrollbar displayed.
I know we could set the height to a smaller percentage or a fixed number of pixels but that will cause problems for us if the font size changes. If a height of 100% - 2em
was valid then that would be effectively what we are trying to define.