CSS keeping the footer at the bottom

Spent enough time trying different methods across the web but only 1 article worked for me using the "push" div layer. Loosely based on Ryanfait: Make a Footer Stick to the Bottom of the Page

Aim:
Header

Left


Right

Footer
copyraw
<div id="container">
     <div id="header"></div>
     <div id="content">
          <div id="left"></div>
          <div id="right"></div>
          <div class="push"></div>
     </div>
     <div id="footer"></div>
</div>
  1.  <div id="container"> 
  2.       <div id="header"></div> 
  3.       <div id="content"> 
  4.            <div id="left"></div> 
  5.            <div id="right"></div> 
  6.            <div class="push"></div> 
  7.       </div> 
  8.       <div id="footer"></div> 
  9.  </div> 
Situation
The header displayed fine. The left and right columns finally got them side by side. But the footer that has a background image was under the left and right columns... The main content layer was overlapping the footer. I tried various z-index's bearing in mind that the footer has to be behind because the main content had a semi-transparent layer that overlapped it half-way.

I managed to fix this by including a div push layer which clears both (even though i had clear:both on the css for my #right div layer). For some reason, it has a more forceful effect in its own separate layer.

In a joomla CMS template though, I wanted the "left" div to take over the whole page if there were no modules positioned in the "right" div. I specified width of left using PHP. This is the CSS though:
copyraw
#container {
	position: relative;
}
#content {
	position: relative;
	top: 0;
	width: 900px; 
	margin: 0 auto;
	min-height: 500px; /* to stop footer coming up on empty pages */
	background-image: url("../images/bg_contentbox.png"); /* semi transparent background */
}
#footer {
	position: relative;
	bottom:0;
	margin:0;
	padding:0;
	width:100%;
	height: 250px; /* height of my footer */
	background-color: #8cc553;
	z-index: -1;
}
#left {
	float: left;
        width:500px;
	margin: 0;
	padding: 0;
}
.push {
	clear:both;
}
#right {
	float:left;
	width:380px;
	margin: 0 0 0 20px;
	padding: 0;
}
  1.  #container { 
  2.      position: relative; 
  3.  } 
  4.  #content { 
  5.      position: relative; 
  6.      top: 0
  7.      width: 900px
  8.      margin: 0 auto; 
  9.      min-height: 500px; /* to stop footer coming up on empty pages */ 
  10.      background-image: url("../images/bg_contentbox.png"); /* semi transparent background */ 
  11.  } 
  12.  #footer { 
  13.      position: relative; 
  14.      bottom:0
  15.      margin:0
  16.      padding:0
  17.      width:100%; 
  18.      height: 250px; /* height of my footer */ 
  19.      background-color: #8cc553; 
  20.      z-index: -1
  21.  } 
  22.  #left { 
  23.      float: left; 
  24.          width:500px
  25.      margin: 0
  26.      padding: 0
  27.  } 
  28.  .push { 
  29.      clear:both; 
  30.  } 
  31.  #right { 
  32.      float:left; 
  33.      width:380px
  34.      margin: 0 0 0 20px
  35.      padding: 0
  36.  } 
Category: Cascading Stylesheets :: Article: 350

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.