I have read all the relevant sticky posts in this forum, and many tutorials outside Sitepoint, and still can’t get this to work.
I have my two navigation bars (one fixed at the top of the viewport, one not), the header, the content and the footer each centred in containers that stretch the entire width of the screen.
I have tried all sorts of sticky footer methods, but each time at least one of the following won’t work: the site staying centred, the footer sticking and the content area filling the whole height of the space between header and footer regardless of how little content there is.
If possible, I would love the height of the footer to be dynamic, but I can live with a fixed height.
Could someone please take a look at my code and help me figure out what is going wrong? Thank you.
html:
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset = "utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="outer-wrapper">
<div id="cart-container">
<nav class="cart-navigation">
<h1 class="site-title">
My Sticky Footer Playground
</h1>
<ul>
<li><a href="#">Shopping</a></li>
<li><a href="#">Cart</a></li>
<li><a href="#">Checkout</a></li>
<li><a href="#">My Account</a></li>
</ul>
</nav><!-- end of .cart-navigation -->
</div><!-- end of #cart-container -->
<div id="header-container">
<header id="masthead">
<nav class="main-navigation">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Sticky Footers</a></li>
<li><a href="#">My Attempts</a></li>
<li><a href="#">My Contact Info</a></li>
</ul>
</nav><!-- end of .primary-navigation -->
</header><!-- end of #masthead -->
</div><!-- end of #header-container -->
<div id="wrapper">
<div id="content">
<section id="main">
<p>Some Content</p>
<p>Some Content</p>
<p>Some Content</p
<p>Some Content</p>
<p>Some Content</p>
<p>Some Content</p>
<p>Some Content</p>
<p>Some Content</p>
<p>Some Content</p>
<p>Some Content</p>
</section><!-- end of #main -->
</div><!-- end of #content -->
</div><!-- end of #wrapper -->
<div class="push"></div>
</div><!-- end of #outer-wrapper -->
<div id="footer-container">
<footer id="site-footer">
<section>
<p>Some Content goes here.</p>
<p>Some Content goes here.</p>
<p>Some Content goes here.</p>
</section>
<section>
<br />
<div class="site-info">
<p>
Copyright 2014
<a href="#">The Sticky Footer Academy</a>
</p>
</div>
</section>
<section id="footer-nav">
<p>Some Content goes here.</p>
<p>Some Content goes here.</p>
<p>Some Content goes here.</p>
</section>
<div class="clear"></div>
</footer>
</div><!-- end of #footer-container -->
</body>
</html>
CSS:
/**** Global Reset ****/
html, body {
height: 100%;
}
html, body, h1, h2, h3, h4, h5, h6, p, a,
ul, li, footer, header, menu, nav, section
{
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
article, aside, footer, header, nav, section {
display: block;
}
/* force a vertical scrollbar to prevent a jumpy page */
html {
overflow-y: scroll;
}
/***** General Site Styles *****/
body {
background: #000;
font-family: Verdana, Arial, sans-serif;
font-size: 100%;
}
#outer-wrapper {
height: 100%;
min-height: 100%;
height: auto !important;
background: #c5a3ca; /* lilac */
margin: 0 0 -160px 0;
}
#wrapper {
width: 1000px;
height: 100%;
margin: 0 auto;
background: #f7caa6; /* orange */
}
p {
margin-bottom: 10px;
}
a:hover {
color: #02750a;
}
.clear {
clear: both;
}
/***** header styles *****/
#header-container {
background: #ffccff;
}
#masthead {
position: relative;
width: 940px;
margin: 0px auto 0 auto;
height: 70px;
padding: 50px 30px 0 30px;
font-size: 90%;
background: #eebbee;
}
.site-title {
position: absolute;
top: 0px;
left: 30px;
font-size: 1.2em;
}
/***** navigation styles *****/
nav ul {
list-style: none;
}
nav ul a {
text-decoration: none;
}
#cart-container {
width: 100%;
padding: 10px 0;
background: #ddd; /* grey */
position: fixed;
top: 0;
z-index: 50;
}
.cart-navigation {
position: relative;
width: 940px;
margin: 0 auto;
padding: 10px 30px;
}
.cart-navigation ul {
float: right;
font-size: 0.9em;
}
.main-navigation {
float: left;
padding: 25px 0 0 30px;
font-weight: bold;
}
.main-navigation ul li, .cart-navigation ul li {
float: left;
margin-right: 25px;
}
.left-navigation ul li:last-child, .cart-navigation ul li:last-child {
margin-right: 0;
}
.left-navigation ul li, .cart-navigation ul li a {
display: block;
}
/***** content styles *****/
#content {
padding-bottom: 20px;
}
/***** #main styles *****/
#main {
padding: 30px;
background: #abcdef;
}
.push {
height: 160px;
}
/***** footer styles *****/
#footer-container {
background: #b1caa3; /* light green */
height: 160px;
}
#site-footer {
width: 940px;
margin: 0 auto;
padding: 20px 30px;
font-size: 90%;
background: #bbb; /* light grey */
}
footer section {
width: 280px;
float: left;
padding: 10px;
margin-right: 20px;
background: #ccc;
}
footer #footer-nav {
margin-right: 0;
}