Reputation: 75
I use box-sizing: border-box;
for all elements and I want to make a sticky footer, I tried many different methods but it doesn't work. Even if I use position: relative;
for footer, then when I use approximately zoom: 33%
there are gap between bottom and footer. Or when he footer position: absolute;
the <section>
goes under footer, or in small zoom there are gap between footer and <section>
. Please somebody, help me.
* {
margin: 0px;
padding: 0px;
}
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
html {
height: 100%;
background-color: purple;
border: 4px dotted purple;
}
body {
position: relative;
min-height: 100%;
background-color: blue;
border: 4px dotted lightblue;
text-align:center;
color: white;
}
nav {
background-color: black;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 70px;
}
header, #page_1 {
height: 800px;
line-height: 800px;
}
header {
background-color: green;
}
#page_1 {
background-color: red;
border: 4px solid yellow;
}
footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 100px;
background-color: black;
color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>...</title>
<meta charset="UTF-8" />
</head>
<body>
<nav>Navigation</nav>
<header>Header</header>
<section id="page_1">Section</section>
<footer>FOOTER</footer>
</body>
</html>
Upvotes: 0
Views: 652
Reputation: 150
Have you already tried to use http://ryanfait.com/sticky-footer/ method?
You have to put all of your contents, except footer, inside a div with a class like "wrapper". Your nav is in fixed position, so you can also keep it outside from the wrapper. Inside of the wrapper, at the last position you put a div with class "push"
then use this css
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important; /* This line and the next line are not necessary unless you need IE6 support */
height: 100%;
margin: 0 auto -155px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
height: 155px; /* .push must be the same height as .footer */
}
Upvotes: 1