Reputation: 4648
I'm trying to make a website where header and footer have fixed position while content scrolls in the middle.
<header style="position:fixed"></header>
<div id="content">some content</div>
<footer style="position:fixed"></footer>
I created what I thought would work but it doesn't. Here's jsFiddle with the whole thing. As you can see, part of content is hidden under the footer and beyond (I can't see 'HELLOWEEN' in the end). What must I change to fix it? Thanx
Upvotes: 13
Views: 69044
Reputation: 250
<header>header</header>
<section>
<div class="push">push</div>
</section>
<footer>footer</footer>
html, body {height:100%; margin:0; overflow:hidden;}
header, footer {display:block; background-color:black; height:10%;}
section {height:80%; background-color:lightblue; display:block; overflow:auto;}
section .push {height:4000px;}
Upvotes: 6
Reputation: 29221
The easiest fix for this is to add padding equivalent to the height of your static header and footer:
#content {
width: 80%;
margin: 0 auto;
padding: 60px 0;
}
Upvotes: 19
Reputation: 14053
If you want the content height to match the browser window (less the header and footer), use javascript to set it (and adjust on window resize events)
Upvotes: 3