What I'm looking for is to have a container div
with any number of headers and footers which would then have another scrolling div
in between the various headers/footers. The catch is here that the headers and footers can't scroll and the container/headers/footers can take any height depending on their content.
I've only been able to get this working with a statically sized header/footer. In the code I've added the problem I've come across: the text in the header/footer may wrap, which will bring it to two lines. So the header should grow to allow this extra line and the content should shrink to give space to the header. Is there any way to do this without using javascript? I will know the number of headers/footers ahead of time if that helps.
This is going to be a component in a page possibly with one or more per page, for example in a 2x2 setup where each takes up a 4th of the browser window. The functionality is mainly needed as the width of the browser might change causing the header content to break a new line. This could be done pretty easily with javascript but I've always heard that resize
event handlers are evil.
For example if my wrapper is 600px
high, I may have 2 headers and 1 footer. Lets say the first header's content causes it to break to a new line, but the second header's doesn't. So the first headers height is 20px
where the second's is 10px
. And lets say the footer's content also causes a line break and thus has 20px
height. This gives us 50px
worth of headers and footers so now the height of the scroller should be 550px
.
Ascii Art:
____________________________________________
| HEADER 1 |
|________breaks to new line__________________|
|____________________________HEADER2_________|
| | ||
| | ||
| This is my scroller | ||
| | ||
| | ||
| | ||
|_________________________________________|_||
| Some |
|_____Footer_________________________________|
HTML:
<div class="wrapper">
<div class="header">
Some<br/>
Header
</div>
<div class="scroller">
Content<br />
Content<br />
Content<br />
Content<br />
...
</div>
<div class="footer">
Some<br/>
Footer
</div>
</div>
CSS:
body{
height:100%;
}
.wrapper{
height:400px;
border-left:1px solid red;
}
.header, .footer{
background-color: #EEE;
height:27px;
}
.scroller{
height:calc(100% - 54px);
background-color: #CCC;
overflow:auto;
}
the red border is to show how far the wrapper goes down, so the footer doesn't show up below. I did this instead of overflow: hidden
simply for debugging.