Getting a footer to stick to the bottom of the page - html

I am currently building a website and require my footer to stick to the bottom of the page - I am struggling somewhat - beneath is an example of my HTML and my CSS - I need the footer to stay at the bottom if the page is small but grow with the page if it gets bigger.
HTML:
<div class="container">
<div class="main">
<!-- some content -->
</div>
</div>
<div class="clear"></div>
<div id="footer">
<div class="container">
<div class="footer_nav">
<h4>Site Map</h4>
<ul>
<li>Home</li>
<li>Example Page 1</li>
<li>Example Page 2</li>
<li>Example Page 3</li>
<li>Contact</li>
</ul>
</div>
<div class="footer_copy">
<p>©<?php echo date('Y');?> Oliver Fletcher<br/>
All Rights Reserved</p>
<h4>Where I learnt...</h4>
<img src="images/accreditations.jpg" alt="Team Treehouse">
</div>
<div class="footer_social">
<img src="images/twitter.png" alt="Twitter">
<img src="images/facebook.png" alt="Facebook">
<img src="images/linkedin.png" alt="LinkedIn">
<img src="images/google.png" alt="Google">
<h4>Get in touch</h4>
oli#thewebshare.co.uk
</div>
</div>
<div class="clear"></div>
</div>
</body>
CSS
html{
height: 100%;
}
.container{
width: 980px;
margin: auto;
min-height: 100%;
_height: 100%;
}
.main{
margin-bottom: -183px;
position: relative;
}
#footer{
width: 100%;
background-image: url('../images/nav_bg.png');
color: white;
font-weight: lighter;
position: relative;
padding: 20px 0;
height: 183px;
}

#footer{
width: 100%;
background-image: url('../images/nav_bg.png');
color: white;
font-weight: lighter;
position: fixed;
bottom:0px;
padding: 20px 0;
height: 183px;
}
Use position:fixed and bottom:0px

One problem I see is the duplicate use of the container class. You should have the container for the content and the container for the footer using separate class names, or you could use the css selector
body > .container
Otherwise, I'd try to switch the css for the .main to have the css rules below. The height and padding needs to be a equal fixed size.
.main
padding-bottom: 100px;
.footer
height: 100px; // FIXED HEIGHT IS IMPORTANT
There's a lot of examples of this on the internet. I used this one and found that it worked well. Hope this helped.

What you want is assign CSS elements to .clear under your #container and above your #footer. You want it essentially push the footer down so it sticks to the bottom.
This tutorial helped me, the whole page is dedicated to a sticky footer.
Sticky Footer Tutorial

Obviously there are many methods to this. Following this tutorial will do the trick as well:
http://www.cssstickyfooter.com/using-sticky-footer-code.html

Related

adding margin-left creates horizontal scroll bar to white space

I'm writing the CSS for my site. I have text that I am putting on top of my background image. My HTML and CSS is below:
HTML
<header class="site-header">
<div class="site-header__menu-icon">
<div class="site-header__menu-icon__middle"></div>
</div>
<div class="site-header__menu-content">
<div class="site-header__btn-container">
Request A Demo
</div>
<nav class="primary-nav primary-nav--pull-right">
<ul>
<li>Home</li>
<li>Services</li>
<li>Why Us</li>
</ul>
</nav>
</div>
</div>
</header>
<div class="section">
<picture>
<img src="assets\images\pepper.jpg">
</picture>
<div>
<div class="section__text-content">
<h1 class="section__title">Company</h1>
<h3 class="section__sub-title">Company Slogan</h3>
<div class="btn-container">
<a class="btn" href="#">Talk To A Specialist</a>
<a class ="btn btn__white btn__pepper-white" href="#">Get A Quote</a>
</div>
</div>
</div>
</div>
CSS
.section {
position: relative;
max-width: 100%;
&__text-content {
position: absolute;
top: 30%;
width: 100%;
margin-left:
}
&__title {
font-size: 7rem;
font-weight: 300;
color: #ffffff;
margin-bottom: 0;
}
&__sub-title {
font-size: 2.5rem;
font-weight: 300;
margin-top: 3%;
margin-bottom: 2%;
color: #ffffff;
}
}
The problem arises when I try to add a margin-left to the .section class in my CSS, because then a blank which space to the right of my screen appears with a horizontal scroll bar in direct proportion to the amount of margin I specified to move to the left.
I know that I could use a simple "background-image" for my css, but I'd prefer to do it this way for responsive imaging (it's how I learned to do it and I'm on a bit of a time crunch).
Any suggestions?
FIXED
My problem was I was writing my margin in relative terms by doing:
.section__text-content {
position: absolute;
margin-left: 10%
}
Which is wrong, because the &__text-content is set to position: absolute
Percentage is relative position, with an absolutely positioned image you need absolute margins (i.e. pixels)

Scaleable sidebar that fits page height but not overlapping footer/header

So I managed to make a sidebar in a div that fit to the left side perfectly but unfortunatly it goes under my footer and header enough that I'm attempting to place a second div inside that sidebar div that will serve to hold actual content.
I'm trying to fit the sidebar to be scale-able (change whenever I adjust the height of the browser to whatever) but not overlap my header or footer or go under it. I have the positioning set to absolute and the header/footer set to fixed.
HTML:
<div id=sidebar"></div>
CSS:
#sidebar {
background-color: #1c1c1c;
left: 0;
width: 300px;
height: 100%;
border-right: #212121 5px solid;
border-top: #212121 5px solid;
border-bottom: #212121 5px solid;
position: absolute;
z-index: 1;
}
This will be used to hold page navigation whereas my nav element is being used to hold site navigation. I'm trying to see if this might involve another language (I only really know HTML/CSS) and also trying to place this sidebar div directly in the center of the left side. Don't quite know how to go about doing that. I believe the footer and header are what one might call 'sticky'. They are position: fixed, again.
I agree with Abdulla. We need to see all your code, but based on what you provided I think you may need to set the following css in your style sheet or in the page head:
html, body{
height:100%;
}
I found this article that may help you http://www.mattboldt.com/css-100-percent-height/
But without knowing more this is all I can provide.
Your Question not clear. As i understood answer is bellow.
Remove these
#header {
position: fixed;
}
#pgdirectory {
position: absolute;
}
#footer {
position: fixed;
}
Add these
.clear
{
clear: both
}
.body
{
float: left;
}
in your HTML
<div id="header">
<nav>
<ul>
<li>Home</li>
<li>Web Development</li>
<li>Fursuits and Mascots</li>
<li>Art Customs</li>
<li>Computer Building</li>
<li>Future Plans</li>
</ul>
</nav>
</div>
<div class="clear"> </div> //New
<div class="body"> //New
<div id="pgdirectory">
<div id="links"> TEXT TEXT TEXT</div>
</div>
<div id="content">
<h1>SITE UNDER CONSTRUCTION</h1>
<p></p>
<h2>Contact Info</h2>
<br>
Email: smith#kempt.us<br>
Skype: mcKempt<br>
</div>
</div> //closing of Body Div
<div class="clear"> </div> //New
<div id="footer">

HTML/CSSmenu at the bottom is clashing with the images in the center

I am new to html,css and am currently working on a page.
I am unable to align the menu at the right bottom side.It is clashing with my 3 pictures in the middle. Also logo at the bottom left keeps changing when ever I make changes to the images at the centre. Kindly go through the code and let me know.
body {
margin: 0;
padding: 0;
}
.background{
position: relative;
}
.background .text {
position: absolute;
top: 300px;
left: 300px;
width: 300px;
}
.logo {
position:absolute;
left: 10px;
bottom: 10px;
}
#bottomnav ul {
list-style: none;
display: inline-block;
width: 100%;
position: absolute;
right:0px;
bottom:0px;
}
#bottomnav ul li {
width: 0%;
float: right ;
text-align:right;
}
.images{
width:250;
height:250;
display:inline;
float:right;
border:2px solid #FFF;
margin-top:300px;
}
<body>
<div class="background">
<img src="images/landing_page.png"/>
<div class="text">
<h1>welcome</h1>
<p>office</p>
<p>ink</p>
</div>
<div class="logo"> <img src="images/logo_03.png"/> </div>
<div class="images">
<img src="images/top1.jpg" width="400" style="float:right"/>
<img src="images/top2.jpg"width="400" style="float:right"/>
<img src="images/top3.jpg" width="400" style="float:right"/>
</div>
<div id="bottomnav">
<ul>
<li>Home</li>
<li>About </li>
<li>Contact Us</li>
</ul>
</div>
</div>
</div>
Divi,
check out clearfix.
http://nicolasgallagher.com/micro-clearfix-hack/
You will need to apply the fix to the image parent container (.images).
Also you are using a lot of absolute positing, when it is not necessarily needed.
You could float the logo left and image container right, while applying an explicit width to each.
Also why do you have .images set to 250 width, and images are 400 width?
I am unsure if this is the answer you're looking for, but this solution solves the problem you were having regarding the menu not showing up on the bottom right hand side (I think is what you were trying to achieve with some of your css): http://jsfiddle.net/swm53ran/72/
I reorganized the structure of your html a little bit because you said the logo should be at the bottom (I'm assuming below the other larger pictures).
<div class="background">
<img src="images/landing_page.png"/>
<div class="text">
<h1>welcome</h1>
<p>office</p>
<p>ink</p>
</div>
<div class="images">
<img src="images/top1.jpg" width="400" style="display:inline-block;"/>
<img src="images/top2.jpg"width="400" style="display:inline-block;"/>
<img src="images/top3.jpg" width="400" style="display:inline-block;"/>
</div>
<div class="logo"> <img src="images/logo_03.png"/> </div>
<div id="bottomnav">
<ul>
<li>Home</li>
<li>About </li>
<li>Contact Us</li>
</ul>
</div>
</div>
heres the css:
#bottomnav {
display:inline-block;
float:right;
}
#bottomnav ul {
list-style: none;
}
#bottomnav ul li {
display: inline-block;
}
Useful tip: when dealing with css, less is more, try to be concise in your styles so that you dont have to write over styles with other styles and force your way around the DOM.
hope this helps/gets you pointed in the right direction.

Unexpected gap right of header and footer when both are set with width:100%?

Problem
When using my phone to view a website i'm creating the site appears and seems to act differently than i expect?
I have a screenshot to demonstrate the problem on said smartphone screen.
Smartphone view
As you can see both the header and footer are not expanding 100% in width as they should, and do when viewed using a desktop browser.
Desktop view
Header CSS
#banner {
background-image: url(images/images/bannersketchBG.jpeg);
float: left;
height: 100px;
width: 100%;
font-size: 36px;
font-style: italic;
}
#banner1 {
float: left;
height: 50px;
font-style: normal;
margin-top: 10px;
padding-left: 10px;
color: #FFF;
font-size: 24pt;
top: 0px;
}
#banner2 {
float: left;
height: 30px;
width: 410px;
font-size: 14pt;
font-style: italic;
padding-left: 30px;
color: #FFF;
}
Footer CSS
.footer {
background-color: #2E2E2E;
word-spacing: normal;
float: left;
color: #FFF;
font-weight: bold;
width: 100%;
height: 100px;
bottom: 0px;
}
HTML
Header
<div align="center">
<div id="banner">
<div id="logo"><img src="images/Joel-Compass-black.png" width="119" height="95" alt="CCFS"></div>
<div id ="banner1">Columbus Car Finder Group</div>
<div id ="banner2">"Exploring your Needs"</div>
</div>
</div>
Footer
<div class="footer">
<div class="footercontainer">
<div id="footerTabsContainer">
<div class='tab one'>
<ul>
<li>Find My Car</li>
</ul>
</div>
<div class='tab two'>
<ul>
<li>About Us</li>
</ul>
</div>
<div class='tab three'>
<ul>
<li>How it Works</li>
</ul>
</div>
<div class='tab three'>
<ul>
<li>How it Works</li>
</ul>
</div>
<div class='tab five'>
<ul>
<li>Contact Us</li>
</ul>
</div>
<div class='tab six'>
<ul>
<li>Home</li>
</ul>
</div>
</div>
<div class="footerinfo">Web Design - CundyTech Copyright South West Car Finder 2013</div>
</div>
</div>
I notice the background image cuts off at the same point too, so could this be an overflow issue?!
Any help or pointers would be greatly appreciated!
PS i know i haven't quite got the finer points of css like using ID's and Classes properly but i am still learning so please dont hate on me too much!
Do not set div to width 100%, it expands by default. What you can try is to remove width property (from footer and header) and set min-width to be the same as your content's (it is a fixed width right?).
Do you have a link to the website that we can access? It is easy to test what works with Chrome/Firefox developer tools.
This generally happens when your content isn't enough to fill up the screen. I personally use calc() to sort it out. You can try this.
.your_header{
height:100px;
}
.your_content{
min-height:calc(100% - 300px);
}
.your_footer{
height:200px;
}
What it does is that it calculates min-height for your_content to 100% - height of your header - height of your footer;
Don't float your #banner or .footer. Check this cool tutorial on positioning to get a better idea: CSS Learn Positioning
Change the positioning of the footer to be fixed.
positioning: fixed; // will make the footer stick to the base of the viewport.
right: 0; // fill space to right
bottom: 0; // stick to the bottom of page
left: 0; // fill space to left
Notice we left out the top attribute... this is because we want that to be set automatically by the height of the inner elements.
You may also want to try position: absolute; and tweak the bottom padding on the body to give a result that will clear the body content and not stick to the viewport.
This should get you heading in the right direction.
As mentioned by #Linek in his answer, in the comments, adding a min-width style to body will solve this problem. I also had to add a min-width to the header, not sure why body didn't do both though?
Solution
Css
Body
{
min-width:1003px;
}

Stop text wrapping

On the following jsfiddle:
http://jsfiddle.net/oshirowanen/4fgkj/
Here is a snippet of the HTML as it would have been too much HTML to post up here if I posted the whole thing:
<div id="main">
<div class="inner">
<ul class="column">
<li class="one">
<ul>
<li>SIDE MENU</li>
<li>SIDE MENU</li>
<li>SIDE MENU</li>
</ul>
</li>
<li class="two">
<ul>
<li class="main_content">
<p>content goes here</p>
</li>
</ul>
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
You will see that I have a menu and some content. The problem is that I don't want the content to wrap around the menu.
How do I stop that from happening?
First of all, don't use li for content, it's only used for displaying lists (such as menus).
Second - to answer your question - a structure like this might do what you want, and is quite regularly used:
HTML:
<div class="wrapper">
<div class="header">
header
</div>
<div class="wrapright">
<div class="right">
right
</div>
</div>
<div class="left">
left
</div>
<div class="footer">
footer
</div>
</div>
CSS:
.wrapper{
width: 90%;
margin: 0 auto;
}
.header{
float: left;
width: 100%;
background-color: #f4f4f4
}
.wrapright{
float: left;
width: 100%;
background-color: #cfcfcf
}
.right{
margin-left: 220px;
background-color: #afeeee;
height: 200px;
}
.left{
float: left;
width: 200px;
margin-left: -100%;
background-color: #98fb98;
height: 200px;
}
.footer{
float: left;
width: 100%;
background-color: #f4f4f4;
}
body {
padding: 0px;
margin: 0px;
}
LIVE DEMO
Of course, you'll have to adjust the CSS to change background colour, padding,... and the HTML to adjust the content. But I think you'll be able to figure that out.
Well, don't tell it to wrap around... in :
#main .column .one {
padding:10px 10px 10px 0px;
float:left;
}
just remove the line
float:left;
You have to set min-height to your css rules (#main .column .one). If you set it, your content will be right the menu, but will not be wrapped around it.
#main .column .one {
padding:10px 10px 10px 0px;
float:left;
min-height:600px;
}
All you need to do is add this to your styles:
.main_content {overflow: hidden;}
However, I must say, using a ul for page layout like that is not a good idea. Semantically, your page content is not an unordered list.