I have this HTML structure:
Dynamic height without scrollbar
I have Similar issue with PrimeNG p_Dialog content and i fixed by below style for the contentStyle
height: 'calc(100vh - 127px)'
Use this:
#head {
border: green solid 1px;
height:auto;
}
#content{
border: red solid 1px;
overflow-y: scroll;
height:150px;
}
A quick, clean approach using very little JS and CSS padding: http://jsfiddle.net/benjamincharity/ZcTsT/14/
var headerHeight = $('#header').height(),
footerHeight = $('#footer').height();
$('#content').css({
'padding-top': headerHeight,
'padding-bottom': footerHeight
});
Flexbox is a modern alternative that lets you do this without fixed heights or JavaScript.
Setting display: flex; flex-direction: column;
on the container and flex-shrink: 0;
on the header and footer divs does the trick:
HTML:
<div id="body">
<div id="head">
<p>Dynamic size without scrollbar</p>
<p>Dynamic size without scrollbar</p>
<p>Dynamic size without scrollbar</p>
</div>
<div id="content">
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
<p>Dynamic size with scrollbar</p>
</div>
<div id="foot">
<p>Fixed size without scrollbar</p>
<p>Fixed size without scrollbar</p>
</div>
</div>
CSS:
#body {
position: absolute;
top: 150px;
left: 150px;
height: 300px;
width: 500px;
border: black dashed 2px;
display: flex;
flex-direction: column;
}
#head {
border: green solid 1px;
flex-shrink: 0;
}
#content{
border: red solid 1px;
overflow-y: auto;
/*height: 100%;*/
}
#foot {
border: blue solid 1px;
height: 50px;
flex-shrink: 0;
}
I don't know if I got it right, but does this solve your problem?
I just changed the overflow-y: scroll;
#content{
border: red solid 1px;
overflow-y: scroll;
height: 100px;
}
Edited
Then try to use percentage values like this: http://jsfiddle.net/6WAnd/19/
CSS markup:
#body {
position: absolute;
top; 150px;
left: 150px;
height: 98%;
width: 500px;
border: black dashed 2px;
}
#head {
border: green solid 1px;
height: 15%;
}
#content{
border: red solid 1px;
overflow-y: scroll;
height: 70%;
}
#foot {
border: blue solid 1px;
height: 15%;
}
Use this:
style="max-height: 300px; overflow: auto;"
Try to avoid fixed height