I have a CSS layout in which a content div has absolute positioning to be able to scroll the content in case of overflow. This content div is positioned within a relative div, since elements above may differ in height (which is decided by their content).
However, my solution only works in Chrome and IE9, the content div doesn’t show a scrollbar in Firefox. And unfortunately my solution also doesn’t work in older browsers. Do you know a better layout to accomplish the above requirements?
Edit:
The layout should fill the viewport 100% width and 100% height, that’s why I probably need to use tables (please correct me if I’m wrong). Also, I prefer a solution without javascript, since I have other javascripts which could manipulate the contents.
My current code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Test</title>
<style type="text/css">
html, body, form { width:100%; height:100%; margin:0; overflow:hidden; }
</style>
</head>
<body>
<table style="width: 100%; height: 100%;">
<tr>
<td style="height: 120px; border: 1px solid #000;">
Top: always same height
</td>
</tr>
<tr style="height: 20px; background-color: Red;">
<td>
Variable height: could push the next row down
</td>
</tr>
<tr style="position: relative; overflow: auto;">
<td style="position: relative; background-color: White; vertical-align: top; overflow: scroll;">
<div style="position: relative;">
<div style="position: absolute; bottom: 0; top: 0; left: 0; right: 0; ">
Content with variable height: needs overflow auto/scroll
</div>
</div>
</td>
</tr>
</table>
</body>
</html>
I can’t figure out how to do it with only css, but I can make it work with javascript.
HTML (inside body):
CSS:
JavaScript (to be placed in head):
The
getDocHeight()function is from here: http://james.padolsey.com/javascript/get-document-height-cross-browser/