I have 2 main divs, the header and a scrolling list contained in a div. I want the header to always remain at the top of the page, and the scrolling list below. The scrollbar should be attached to the scrolling div and not to the whole page, i.e. the scrollbar does not appear on the right of the header, just the scrolling div.
This is what i'm trying to achieve:
______________________
|_______header_______|
| |*|
| Container Div |*|
| |*|
| |*|
| |*|
| |*|
| |*|
----------------------
* = scrollbar
The layout should be fluid and if the window is stretched vertically, only the container div and it's scrollbar should get longer.
I don't want to position the header position: fixed;
as then the scrollbar will be on the right of it instead of underneath it.
Found the flex magic.
Here's an example of how to do a fixed header and a scrollable content. Code:
* The advantage of the flex solution is that the content is independent of other parts of the layout. For example, the content doesn't need to know height of the header.
For a full Holy Grail implementation (header, footer, nav, side, and content), using flex display, go to here.
Here is a demo. Use
position:fixed; top:0; left:0;
so the header always stay on top.You need to use js get better height for body div
HTML:
CSS: