I am working on some homework. I cannot get the footer to fit properly at the bottom of the page not matter how much I fill each individual page…can anyone give me a pointer? The width and height of the wrapper div have to be set to the presets. I want the footer to sit at the bottom of the page. Body content should be filled and the footer should be sitting at the bottom of the page. The top should be 50px into the bottom of the body.
body
{
background-color: #ffffff;
}
.wrapper
{
width: 960px;
height: 700px;
background-color: #D3D1C2;
margin-left: auto;
margin-right: auto;
margin-top: 20px;
}
.masthead
{
height: 150px;
width: 960px;
background-color: #000;
}
#nav-wrapper
{
width: 960px;
margin: 0 auto;
padding: 20px 0;
background: #3D3331;
}
ul#nav
{
font-family: Verdana;
font-size: 14px;
list-style: none;
margin: 0 auto;
padding: 0;
width: 960px;
overflow: auto;
}
ul#nav li
{
display: inline;
}
ul#nav li a
{
text-decoration: none;
display: block;
padding: 5px 21px;
background: #5F3222;
color: #eee;
float: left;
text-align: center;
border-top: 2px solid #815444;
border-right: 2px solid #3d1000;
border-bottom: 2px solid #3d1000;
border-left: 2px solid #815444;
}
ul#nav li a:hover
{
background: #a37666;
color: #000;
border-top: 2px solid #815444;
border-right: 2px solid #c59888;
border-bottom: 2px solid #c59888;
border-left: 2px solid #815444;
}
.body
{
}
.footer
{
clear: both;
width: 960px;
height: 50px;
background: #000;
margin-bottom: 10px;
}
h1
{
text-align: center;
}
HTML:
<html>
<head>
<!--I am using TextWrangler to do my html css editing on my Mac-->
<link rel="stylesheet" type="text/css" href="style.css" />
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<title>
KG Doors
</title>
</head>
<body>
<div class="wrapper">
<div class="masthead">
</div><!--end the masthead div -->
<div id="nav-wrapper">
<ul id="nav">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
<div class="body">
<br/>KG Doors offers replacement of:
<br/>- Springs
<br/>- Cables
<br/>- Openers
<br/>- Keypads
<br/>- Transmitters
<br/>- Garage Doors
<br/>- Sections
</div><!--end the body div -->
<div class="footer">
</div><!--end the footer div -->
</div><!--end the wrapper div -->
</body>
</html>
Let’s Create a sticky footer!
We’ll start out with some nice clean markup:
…and we’ll add some basics to our CSS:
To achieve a “sticky” footer (a footer that sticks to the bottom of the page), set
height:100%;on the<html>and<body>elements. This will prevent the element from shrinking vertically to the size of its contents:Then set a
box-sizingofborder-box(this is css3 so add your desired vendor prefixes), and amin-heightof100%on the#pagebodyelement (main page container):Now that the main container of the page has a minimum height of 100% the footer should be pushed down below the viewport (so you have to scroll to see it).
Next, on the
#pagebodyelement, add a top padding that is equal to the height of the header (80px) and a bottom padding that is equal to the height of the footer (40px):Next, on the
#pagebodyelement, add a negative top margin equal to the height of theheader, and a negative bottom margin that is equal to the height of the footer:Then add
position:relative;to theheaderelement so it is not underneath the#pagebody:And we’re done! Try taking out some of the paragraphs in the example. The footer still sticks to the bottom of the page! 🙂
I hope this was helpful!
-Daniel