I have a parent div containing a header section and a body section. The parent div has a maximum height, but no minimum height.
See this example: https://jsfiddle.net/1o79a6nc/2/
#cont {
padding: 5px;
background-color: red;
max-height: 150px;
max-width: 50%;
}
#body {
background-color: blue;
overflow-y: auto;
overflow-x: hidden;
}
#head {
background-color: green;
}
<div id='cont'>
<div id='head'>
<div>Head</div>
</div>
<div id='body'>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
<div>Body</div>
</div>
</div>
I want the body to only expand so that it fits inside the parent (including the padding), and then apply scroll bars when necessary.
As the example shows, I have tried overflow-y: auto
, however this is not working as I have intended.
Edit: I want scroll bars to only appear on the body, so that the head section and the parent bottom padding are always visible.