CSS Footer at bottom of page - css

I want a footer to stay at the bottom of the page. So I created a DIV with min-heigt:100% and a DIV with no height setting for animating an ajax content loads:
HTML:
<div class="main">
<div class="header navi>…</div>
<div class="animater">
<!-- content goes here -->
<div class="footer">
<!-- footer stuff goes here -->
</div>
</div>
</div>
CSS:
.main {
min-height:100%;
margin-left:auto;
margin-right:auto;
position:relative;
}
.header {
// height, width, margin, position
}
.animater {
// empty
}
.footer {
bottom:0px;
position:absolute;
}
When I load the page and the content is much smaller than my screen everything works perfect. The Footer is at the bottom of the screen as supposed.
I'm now animating the animater using CSS keyframes. When the out animation ends, I'm replacing the content of animater and enimate it back in again. When the content is smaller then the screen again, the footer is at the top of my animater. But when I'm reloading the page "manually" (so that the content does not get animated), the footer is positioned properly.
So I need a footer that sits at the bottom of the content whatever height the content has. I cannot give the animater min-height 'cause it is not at the top of the page.

This example I made shows the minimum css needed to get a footer to stay down. http://jsfiddle.net/meBv3/
The HTML
<div class="wrapper">
<div class="page">
page here
</div>
<div class="footer">
Content for class "footer" Goes Here
</div>
</div>
the CSS
/* THIS IS THE MIN STYLE NEEDED TO GET THE FOOTER TO STAY DOWN */
html, body{
height:100%; /* to keep .footer on bottom */
margin:0; /* to get rid of scroll bar, because (100% + default margin = scroll) */
}
.wrapper {
min-height: 100%; /* to keep .footer on bottom */
position: relative; /* must be relative or .footer will cover content */
}
.page {
padding-bottom:2.2em; /* MUST have padding on the bottom => .footer, or .footer will cover content 8*/
}
.footer {
position: absolute; /* to keep .footer on bottom */
bottom: 0px; /* to keep .footer on bottom */
height:2em; /* height must be smaller then .page's bottom padding */
}

Related

Issue in sticky footer content in html5

I have created simple webpage using html5 and css.
I have created sticky footer with 4 columns and each column have vertical navigation menu.
Here is my code:
<footer>
<div id="footer">
<div class="footer-column" id="footer_column1">
Home
</div>
<div class="footer-column" id="footer_column2">
about us
</div>
<div class="footer-column" id="footer_column3">
contact us
</div>
<div class="footer-column" id="footer_column4">
Blogs
</div>
</div>
</footer>
and this is for css:
#footer {
position:absolute;
clear:both;
bottom:0;
color:#000;
width:100%;
height: 50px;
background:#fff;
left:0;
}
.footer-column {
float: left; /* Push the div as far up-left as it can be put */
width: 25%; /* Make sure to subtract the padding */
padding: 10px; /* We want padding on all sides to make things look nice */
text-align:center;
}
Now page looks like : s22.postimg.org/l0l6y85o1/Untitled_1_copy.png
If i increase the height of footer, it will be hidden background of slideshow.
Can anyone help me, how to fix this. Thanks in advance.
You have given absolute positioning to footer so it will stay there, now your page is basically overlapping it. You should use relative layout for your page.
I would suggest you to use bootstrap for this. Here is a simple example or this.
Regarding z-index - If you will give higher z-index to your footer say 999999 then it will be on top (higher than other elements on page).
Z-index will not actually help you with positioning. Always something will be hidden. If you want your footer to be right at bottom of the page then do not use absolute positioning and it will be pushed down.
Try:
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 100px;
}
#footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 100px;
}

inline divs that adjust width automatically

In case of 2 divs. one is static and other is dynamic. That is one div width should be 400px (This one I call as static div as it has static width) and the other div should occupy the rest width (This one I call as dynamic div as it has dynamic width). And, the dynamic div has no fixed width and should occupy all the remaining and should float right where as static div floats on left. My main issue is while stretching the browser when the website is active, there comes the major issue. I neither want the divs to overlap or go down. I want the dynamic div's width to adjust such that the menus remain constant.
My example code:
<style type="text/css">
body{
margin:0px;
}
#wrap{
width:100%;
min-width:1000px;
}
#static{
width:400px;
float:left;
background-color:#930; /* Just to differentiate DIV */
}
#dynamic{
float:right;
background-color:#CF0; /* Just to differentiate DIV */
}
.menus{
display:inline-block;
padding-left:5px;
padding-right:5px;
width:80px;
}
</style>
<div id="wrap">
<div id="static">
Logo comes here
</div>
<div id="dynamic">
<div class="menus">
Menu1
</div>
<div class="menus">
Menu1
</div>
<div class="menus">
Menu1
</div>
<div class="menus">
Menu1
</div>
<div class="menus">
Menu1
</div>
<div class="menus">
Menu1
</div>
</div>
</div>
In the above code, menus are displayed pretty far from logo whereas I need them to be just besides logo (but shouldn't be float left.) And, the width of the dynamic div should be adjusted such that they are displayed without wasting space.
If this is out of CSS then anybody please suggest me with JS/jQuery code.
Any help is highly appreciated.
Just remove float:right from #dynamic:
JS Bin demo
To evenly distribute the menu items, do this:
#dynamic
{
background-color:#CF0; /* Just to differentiate DIV */
display:table;
width: 100%;
}
.menus
{
display:table-cell;
text-align:center;
}
JS Bin demo: http://jsbin.com/emulux/2
A third installment...
Set a percentage width on the static div like 20% and set 80% to the dynamic div:
#static
{
float:left;
background-color:#930; /* Just to differentiate DIV */
width: 20%;
}
#dynamic
{
background-color:#CF0; /* Just to differentiate DIV */
display:table;
width: 80%;
}
.menus
{
display:table-cell;
text-align:center;
}
JS Bin demo
THis should do the trick..
DEMO
#static{
width:400px;
float:left;
background-color:#930; /* Just to differentiate DIV */
display:inline; /*New Line */
}
#dynamic{
/* float:right;*/
background-color:#CF0; /* Just to differentiate DIV */
width:100%;
}

Unable to get footer occupy the rest of the screen

I'm using bootstrap without any modification. The layout is pretty simple. I've a top navbar. Then the main container. And in the end, I've a footer. Something like:
<head>
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
background-color: #ECECEC;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
// navbar elements
</div> <!-- end of class navbar -->
<div class="container">
// fluid-row class with two column structure
</div> <!-- end of class container -->
<div class="footer">
<div class="container"> <!-- using container to left-align footer to the main content -->
// some content
</div> <!-- end of class footer -->
</body>
There are two things that am not able to do.
1) Whenever there's less content in the main container class, I need the footer to be aligned at the bottom of the screen. I tried min-height:100% but am doing something wrong.
2) I need the footer to have a different background color and footer should occupy the rest of the screen once the main container ends. The footer can have a minimum height or take the height as per the content inside the footer.
.footer {
height:80px;
margin-top:-80px;
position:relative;
clear:both;
padding-top:20px;
background-color:#F4F4F4;
border-top:1px solid #ddd;
clear:both;
}
What's going on here?
JSfiddle: http://jsfiddle.net/m7dkt/13/
This should do the trick for you: http://jsfiddle.net/panchroma/ru2BD/
Instead of trying to figure out how to color the footer and have it extend to the bottom of the page, set the body color as what you need for the footer colour, then colour the content area between the header and the footer.
body {
background-color: #F4F4F4; /*same as footer color */
}
/* don't need to explicitly set footer colour now, it's set above */
/* .footer {
background-color:#F4F4F4;
} */
/* wrap page content and set the background colour */
#wrapper{
padding-top:10px;
background-color:#ECECEC;
}
Update
If I understand you correctly you also want the footer text to be aligned to the bottom of the window. See how this looks:
http://jsfiddle.net/panchroma/D7YXP/
It's a combination of the technique above with a sticky footer.
I used this trick: I hope it will be useful for you.
HTML
<div id="wrap">
<div id="clearfooter"></div>
</div>
<div id="footer">
</div>
CSS
#clearfooter {
display: block;
height: 50px;
}
#wrap{
padding-bottom:69px;
overflow:hidden;
}
#footer{
width:100%;
height:69px;
background:#8dc63f;
overflow:hidden;
clear:both;
color:#FFF;
position:fixed;
bottom:0;
opacity:0.9;
}
Try adding the css below to your css:
html, body, #wrapper{
height:100%;
}

Difference between CSS sticky footer implementations?

I've found 2 different implementations of a CSS sticky footer:
Ryan Fait sticky footer - http://ryanfait.com/sticky-footer/
Steve Hatcher sticky footer - http://www.cssstickyfooter.com/
Could someone explain the difference between how each of them work?
And if there are other known implementations, could you please post a comment or edit this question?
They are pretty similar in terms of function. The first forces a div to the full height of the page and then give it a negative margin the size of the footer.
html, body {
height: 100%; /*set 100% height*/
}
.wrapper {
min-height: 100%; /*content 100% height of page */
height: auto !important;
height: 100%;
margin: 0 auto -142px; /* negative value causes wrappers height to become (height of page) minus 142px, just enough room for our footer */
}
.footer, .push {
height: 142px; /*Footer is the footer, push pushes the page content out of the footers way*/
}
What this does is makes sure that all content within the wrapping div is 100% of the page height minus the height of the footer. So that as long as the footer is the same size as the negative margin it will stick in the gap left and appear at the bottom of the element.
The second also forces the content to be 100% of the height of the page.
html, body {height: 100%;} /*set 100% height*/
#wrap {min-height: 100%;} /* make content 100% height of screen */
It then creates a space at the bottom of the main content the same size as the footer.
#main {overflow:auto;
padding-bottom: 150px;} /* wrapper still 100% height of screen but its content is forced to end 150px before it finishes (150px above bottom of screen) */
Then using position relative and a negative top margin forces the footer to appear 150px above its normal position (in the space it just made).
#footer {position: relative;
margin-top: -150px; /* Make footer appear 150px above its normal position (in the space made by the padding in #main */
height: 150px;
clear:both;}
Note: This only works so long as your page content is kept within .wrapper and #main inside #wrap respectively, and your footer is outside of these containers.
If you didn't understand any part of that leave me a comment and I'll try to answer it.
Edit: In response to user360122
HTML markup for first:
<html>
<body>
<div class="wrapper">
<!--Page content goes here-->
<div class="push">
<!--Leave this empty, it ensures no overflow from your content into your footer-->
</div>
</div>
<div class="footer">
<!--Footer content goes here-->
</div>
<body>
</html>
HTML markup for second:
<html>
<body>
<div id="wrap">
<div id="main">
<!--Page content goes here-->
</div>
</div>
<div id="footer">
<!--Footer content goes here-->
</div>
</body>
</html>
Remember to include the stylesheet and declare doctype .etc (these aren't full html pages).
There is an example in the bootstrap documentation which seems to be very simple: http://getbootstrap.com/examples/sticky-footer/
No wrapper or push needed.
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
#footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}

DIVs anchored to top and bottom of parent div

This is probably a very dummy question, don't throw your shoes at me :)
Consider having HTML like this:
<div class="container">
<div class="header">
</div>
<div class="body">
</div>
<div class="footer">
</div>
</div>
I want 'header' and 'footer' to be anchored to the parent's top and bottom respectively, and 'body' to grow easily to fit all available space.
What would the CSS look like to achieve this?
EDIT: Maybe I'm saying this wrong (i'm not exactly a web developer :) ), but what I need is to have some part of a div always attached to its bottom. So when div grows this part (which might have a fixed size) would go lower with the div's lower end. But all this doesn't mean attaching a div to the bottom of browser's window.
If I understand your question correctly, you require some really basic css.
body { background: black; }
.container { width: 960px; }
.header { height: 100px; background: #ddd; }
.content { padding: 10px; }
.footer { height: 100px; background: #ddd; }
Your div's are not floated, so will stack on top of each other like pancakes.
If you want the footer to be "sticky", see here for a solution...
http://ryanfait.com/sticky-footer/
Here you go:
Example page - footer sticks to bottom
this will have the content right
between the footer and the header.
no overlapping.
HTML
<header>HEADER</header>
<article>
<p>some content here (might be very long)</p>
</article>
<footer>FOOTER</footer>
CSS
html{ height:100%; }
body{ min-height:100%; padding:0; margin:0; position:relative; }
body:after{
content:'';
display:block;
height:100px; // compensate Footer's height
}
header{ height:50px; }
footer{
position:absolute;
bottom:0;
width:100%;
height:100px; // height of your Footer (unfortunately it must be defined)
}
Try this: Set position: relative on the parent div. Set position: absolute on the inner div(s) and set both the top and the bottom properties; don't set height. The inner div(s) should stretch vertically with the parent, as required. (Doesn't work in IE6 and below unfortunately).

Resources