Got stuck while trying to make an element in website behave like this:
<div class="for100procHeight">
<div class="header">fixed top</div>
<div class="content">long text with scrolling content</div>
<div class="footer">fixed bottom</div>
</div>
Quick reminder of css height:
- The percentage is calculated with respect to the height of the generated box's containing block.
- If it has block-level children, the height is the distance between the top border-edge of the topmost block-level child box<...>
- However, if the element has a non-zero top padding and/or top border, or is the root element, then the content starts at the top margin edge of the topmost child<...>
Optimistic solution was:
.for100procHeight { height: 100%; }
.header, .footer { height: 20px; }
.content { height:100%; overflow:scroll; }
/* failed badly: footer didn't fit into the window (heightwise) */
With diminished optimism another attempt was made:
<div class="for100procHeight">
<div class="header">fixed top</div>
<div class="footer">fixed bottom</div>
<div class="wrapper">
<div class="content">long text with scrolling content</div>
</div>
</div>
.for100procHeight { height: 100%; }
.header, .footer { position: absolute; height: 20px; }
.content { height:100%; overflow:scroll; }
.header { top: 0px; left: 0px; }
.footer { bottom: 0px; left: 0px; }
.wrapper { padding-top: 20px; padding-bottom: 20px; }
/* failed badly: scroll down arrow was behind footer */
/* failed badly: scroll down arrow didn't fit into the window (heightwise) */
This looks almost as it should except that height is 100% of browser window (causing bottom of element to be outside of visible area). Margins/Paddings/Wrappers/etc don't change that.
I have looked at Complex height in CSS however JS support on client/element height looks even more fascinating.
Edit:
Copy paste from complex-height-in-css with extension
---------------------------------------
| fixed top | | fixed top | |
|-----------| |-----------| |
| long |^| | long |^| |
| text |_| | text |_| |
| with |_| | with |_| |
|scrolling| | |scrolling| | |
| content | | | content | | |
|-----------| |-----------| |
| fixed bott| | fixed bott| |
--------------------------------------
i realize having two of those was not mentioned, but neither was having <div class="for100procHeight">
as entire page content.
Solution:
<html>
<head>
<style>
html, body {
height: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
}
.page {
position: absolute;
height: 100%;
width: 100%;
}
.content {
width: 100%;
height: 100%;
overflow: scroll;
overflow-x: hidden;
}
.content .inner {
padding-top: 30px;
padding-bottom: 30px;
}
.top {
width: 100%;
margin-left: -17px;
position: absolute;
top: 0px;
left: 0px;
height: 30px;
background: url('background.gif');
}
.bottom {
width: 100%;
margin-left: -17px;
position: absolute;
left: 0px;
bottom: 0px;
height: 30px;
background: url('background.gif');
}
.top span, .bottom span {
padding-left: 17px;
z-index: 2000;
}
.top span, .bottom span {
display: block;
width: 100%;
}
#list2.page {
margin-left: 110%;
}
</style>
</head>
<body>
<div id="list1" class="page">
<div class="top"><span>top</span></div>
<div class="bottom"><span>bottom</span></div>
<div id="listContent" class="content">
<a id="page1" name="page1" style="width:1px;"></a>
<div class="inner">
...
</div>
</div>
</div>
<div id="list2" class="page">
<div class="top"><span>top</span></div>
<div class="bottom"><span>bottom</span></div>
<div id="listContent" class="content">
<a id="page2" name="page2" style="width:1px;"></a>
<div class="inner">
...
</div>
</div>
</div>
</body>
</html>