I have an HTML page whose structure is like this -
<html>
<head>...</head>
<body>
<div id="header">...</div>
<div id="in-body">...</div>
<div id="footer">...</div>
</body>
</html>
My aim is to make the #header
& #footer
static at top & bottom of the page, respectively, but there is always some space left after the #footer
.
I thought if adding the % height
s of the div
s will give 100%
, I could cover the whole body
area, but still even as of now I'm using (18 + 75 + 3)% = 96%
of the height
, there is still some space left after the #footer
.
The CSS for this is -
html {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
body {
height: 97.9%;
margin: 8px 8px 0px 8px;
}
#header {
height: 18%;
margin: 0;
}
#in-body {
height: 75%;
margin: 0;
}
#footer {
height: 3%;
margin: 0;
}
I've checked from Chrome's Developer Tools that there is no extra margin
or padding
anywhere.
If I try to make the addition 100%
, a scroll bar appears, and there is still that space left, which doesn't belong to any element (from Chrome Developer Tools), not even html
, but it remains just there.
I've used body-height: 97.9%
because I only want all the visible html-height
without overflow.
I've checked this in IE11, Chrome 50 and Firefox 46, and it is the same in all.
Keeping html { overflow: hidden }
hides it in IE & Firefox, but not in Chrome.
What is causing this? Is there any way other than using overflow
to remove it?
If I'm wrong in my approach anywhere, feel free to correct me.
Here's the complete code.
Thanks.
Edit: I tested the code mentioned above with each tag having a different bg-color and it works fine. So, it is my code that is causing the trouble. Help me, please.
you have after footer element in your code, so remove it and see if you get what you wanted. – fbxmg Apr 28 '16 at 08:35
tag. It's because it's important to share a working fiddle reproducing the issue (read the help center to more info). I vote to close this as typographical error. Good luck! – Marcos Pérez Gude Apr 28 '16 at 08:39