How to make a sticky footer i have tried on google found some results but didn't get the exactly how this is working so here i have made some rough mockup to understand the things deeply i have three div's #header, #container, #footer.
So if i will remove the #container than footer should not be go anywhere that should stable on his permanent location.
explain with simple method everyone will understand easily...
see the my fiddle:-http://jsfiddle.net/dZDUR/5/
Give height:100% to html, body & main container. When you give height:100% to .container it's push down the footer & after that we give footer margin from the top same as his height. Like this:
html,body{
height:100%;
}
.header {
background:red;
width:500px;
height:100px;
}
.container {
background:yellow;
width:500px;
height:100%;
}
.footer {
background:green;
width:500px;
height:100px;
margin-top:-100px;
}
HTML
<div class="container">
<div class="header">
</div>
</div>
<div class="footer">
</div>
Check this http://jsfiddle.net/dZDUR/8/
http://jsfiddle.net/dZDUR/6/ give the footer the position: fixed value and you can position is like you want. in this example with top: 200px; so it will stay there even without the #container
I think this will help you.
http://jsfiddle.net/4VEqh/
Even if you remove the container div, footer will not move.
You can use absolute positioning via CSS. I'm assuming your footer and header are not nested in the container since removing the container would then remove the footer. So, supposing you have this structure:
<div class="header"></div>
<div class="container"></div>
<div class="footer"></div>
The footer div has to be absolute positioned (taking it out of the flow), with the bottom set to 0 - e.g.:
body {
position:relative;
}
.footer {
position: absolute; /* or position:fixed for scrolling */
bottom: 0;
}
you may or may not need to set position:relative on the body (is this default behaviour?).
If there is scrolling in the picture, like QQping mentions, use position:fixed instead of position:absolute (otherwise same code)
Related
i am trying to make my website, but i have problem with size of screen. I want to make it bit responsive, and my layout is - header on top, then menu and footer, but its on 25% of width, and i dont know how to resize it to 100% height.I want it look like this: http://s32.postimg.org/9pa325s3p/img.png
My Code:
<header>header </header>
<section id="menu">menu</section>
<footer>footer </footer>
css code is not important.
Try to use vh units there:
#menu {
height: calc(100vh - 80px);
}
Here's a solution that should work in pre-CSS3 browsers.
The menu and footer are inside a wrapper div. The wrapper div gets height:100% and starts at the top of the page using margin-top:-40px. The wrapper div gets position:relative so that all elements inside are positioned relative to this container element.
For the menu, we position absolutely with top:40px so we don't overlap the header, and bottom:40px so we stop before the footer.
Footer styles are obvious - position:absolute with bottom:0 so we hit the bottom of the page.
<style>
header {
height:40px;
background-color:yellow;
}
#menufootercontainer {
position:relative;
height:100%;
margin-top:-40px;
position:relative;
}
#menu {
width:80px;
position:absolute;
top:40px;
bottom:40px;
background-color:green;
}
footer {
width:80px;
height:40px;
position:absolute;
bottom:0;
background-color:red;
}
</style>
<header>header</header>
<div id="menufootercontainer">
<section id="menu">menu</section>
<footer>footer</footer>
</div>
The simplest thing you can do is wrap the section and footer elements in a 'wrapper' div, or any other block level element (aside, section, nav, etc.) you like, like this:
<div ID="sidebar-wrapper">
<header>header </header>
<section id="menu">menu</section>
<footer>footer </footer>
</div>
Once you do that, it's as simple as give the #sidebar-wrapper a height of 100% and width of 25%. And finally, give your menu and footer the desired heights as percentages.
#sidebar-wrapper {
width: 25%;
height: 100%;
}
section {
height: 90%;
}
footer {
height: 10%
}
Once that's done, your layout should be just as it is in the picture.
P.S: if you plan to have navigation links in that section element (which I imagine you do), you should use 'nav' instead to be more semantic :).
My html and body elements are not filling 100% of the viewport, which is leaving me with approx 200px of blank space below my footer. I have played with the inspector to try and resolve this problem but nothing is working perfectly.
It is worth noting that I have 3x sidebars that are activated from the top menu (Artists, About, History) and these need to be 100% height too, I feel that this probably has something to do with the issue.
Any help much appreciated, I haven't included any markup here as the problem is quite broad.
Thanks
http://workshop.oakdesignstudio.com/dwl/
The easiest is to give your body position: relative;
So
html{
height: 100%;
}
body{
height 100%;
position: relative;
}
you forgot to give position value to your footer tag.
add this code on line no. 475
footer {
position:absolute;
}
The page structure is really important especially for cross-browser compatibilty. This will help with your sidebars as well;
<body>
<div id="wrapper">
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</div>
</body>
and
html,
body {
margin:0;
padding:0;
height:100%;
}
#wrapper {
min-height:100%;
position:relative;
}
#header {
}
#content {
padding-bottom:100px; /* Height of the footer element */
}
#footer {
width:100%;
height:100px;
position:absolute;
bottom:0;
left:0;
}
Original source http://www.cssreset.com/demos/layouts/how-to-keep-footer-at-bottom-of-page-with-css/
Try it yourself and you'll be thankful for that layout structure!
I'm actually designing my website, it's going to be a one HTML page using javascript to switch between divisions.
I'm using a wrap division where my banner/header, text container and my footer are relative positioned.
I want my footer to be at least to the bottom of the window when there is not enough content, so I'm trying to put a min-height to my text container.
Like this the website would occupy at least all the windows in it's height.
My HTML code (a part ^^)
<div id="wrap">
<div id="banner"></div>
<div>
<div id="whoami" class="corpus"></div>
<div id="etc" class="corpus">There is different divisions like these, I'm switching through thoose using jQuery, but that's not important there. I'm trying to put a min-height to get the footer at the bottom of the windows if there not enough content. I can't pass the footer in absolute position</div>
</div>
<div id="footer"></div>
</div>
The CSS that goes with this
html, body {
margin:0;
padding:0;
background:#fff;
height:100%;
}
#wrap {
background-color:#ff0;
min-height:100%;
width:1000px;
left:50%;
margin-left:-500px;
position:absolute;
}
#banner {
background-color:blue;
height:150px;
width:1000px;
position:relative;
}
.corpus {
width:800px;
min-height:100%; //I tried this : min-height : calc(100% - 260px); it didn't work.
margin-left:100px;
background-color:grey;
position:relative;
height:auto;
margin-top:5px;
}
#footer {
height:100px;
width:1000px;
background-color:purple;
position:relative;
z-index:1;
bottom:0;
margin-top:5px;
}
A little Fiddle for the road :http://jsfiddle.net/yoshino78/bn455/1/
Since #wrap is a positioned element and you've already applied bottom:0 for the footer, all you've to do is
Simply apply position:absolute to the footer, so that it'll stay at the bottom of #wrap regardless of the content inside it.
Demo
Side note: you also might want to apply padding-bottom to #wrap equal to the height of footer so that content won't get hidden behind the footer
I made this:
HTML:
<body>
<div id="header" >
</div>
<div id="main" >
</div>
<div id="footer" >
</div>
</body>
CSS:
body
{
margin:0px;
}
#header
{
width:100%;
background-color:black;
height:60px;
}
#main
{
width:300px;
border:1px dotted black;
margin:0 auto;
}
#footer
{
width:100%;
background-color:black;
height:40px;
position:absolute;
bottom:0px;
}
http://jsfiddle.net/VpwQQ/2/
But as you can see, the main div doesn't have a height.
Then I replaced my css by that:
body
{
margin:0px;
}
#header
{
width:100%;
background-color:black;
height:60px;
}
#main
{
width:300px;
border:1px dotted black;
position:absolute;
margin:0 auto;
bottom:60px;
top:80px;
}
#footer
{
width:100%;
background-color:black;
height:40px;
position:absolute;
bottom:0px;
}
http://jsfiddle.net/VpwQQ/1/
But then, the horizontal center doesn't work.
How can I do this design (div centered and that takes all the page in height between the header and footer with a 20 px magin) ?
I'm not sure what you're trying to do, but I'll give my explaination of what's going to happen with your code:
Your #main div doesn't have a height because it doesn't have a height CSS property, nor does it have any content.
You should add either a height: 100px or just add some content and you will see it gets a height.
The reason why I ask what you want to do is because you're not very clear as to what you want your final product to look like.
You're going to have another problem with the footer. If you use position absolute it sticks to the bottom at the moment. Set the height of the #main div to something ridiculously high and you'll see that when you have to scroll down the page the footer stays where it is. See http://jsfiddle.net/VpwQQ/3/
You should use position: fixed but this will keep it on the bottom of the WINDOW and not the DOCUMENT. So then you get into the problem of having to use Javascript in order to measure the document height and setting positions appropriately. Not sure what you're trying to do, but if you're just trying to lay out a website then use standard relative positioning to push the footer down naturally below the #main div.
Edit:
See http://jsfiddle.net/VpwQQ/4/ if you're just trying to set up a normal website layout.
If you want the footer to "stick" to the bottom of the page all the time then you will need to use position: fixed but I don't think this works across all browsers. See http://jsfiddle.net/VpwQQ/6/
Lastly, to get both footer and header to "stick" see http://jsfiddle.net/VpwQQ/8/
I added a div inside #main.
Main now has a 100% width.
Inside, put a div of 300px, with no absolute position.
I forked your fiddle: http://jsfiddle.net/8U9P6/
Personnally I prefer the javascript solution and not using the absolute position. But this solution seems to work.
Add and overflow to contain the content in the inside div: http://jsfiddle.net/M2nZc/
Note that the page will not grow as it is absolute position.
You can't use automatic margins on an absolutely positioned element, as it's not in the document flow any more.
Use width: 100% on the #main div, then put another element inside it that you center using automatic margins.
Demo: http://jsfiddle.net/Guffa/VpwQQ/9/
Note: You may need to use height: 100% on the body and html elements for the bottom sizing to work on the #main element.
Once you fill your #main div with content, it will automatically gain height according to the content. You can simply fill it with a few paragraphs of lorem ispum to simulate content. You can now remove the absolute position and positioning CSS.
Centering a div using the "0 auto" shorthand only works when the parent element (which, for the #main div, is the body element) has a defined width. To do this, try giving your body element a width of 100%. Doing this is something that you might want to make a habit of in you CSS.
To have your #main div always be 20px below the #header div, simply add 20px of margin-bottom to your #header div. Do the same below the #main div to space the footer.
Summed up (without the footer at the bottom, for now) your CSS might read something like this:
body {
width: 100%
margin: 0px;
}
#header {
width: 100%;
height: 60px;
margin-bottom: 20px; /*here we space the header 20px from the next element*/
background-color: black;
}
#main {
width: 300px;
margin: 0 auto 20px auto; /*we append the margin to include 20px of spacing at the bottom*/
border:1px dotted black;
}
#footer {
width:100%;
height:40px;
background-color:black;
}
Example: http://jsfiddle.net/WEx3j/
If you want the footer to be 'sticky' (always be at the very bottom of your website), I advise you to employ this method.
I hope this clarified a few things.
Problem
I'm using this implementation of a CSS sticky footer. It does:
html,body{
height:100%;
}
I use (would like to) use a repeating background, however, the height:100% causes this issue:
(image from another sticky footer question with unsatisfactory answers)
It's my understanding that the image gets sized to the size of the window at rendering, and thus never sizes past that.
Question
Is it possible to continue to use my existing choice of CSS sticky footer with a repeating background image rendered completely on long pages
OR
is there another option of CSS sticky footers which does support the repeating background?
For reference
<div id="wrap">
<div id="header">Header text</div>
<div id="main">
</div>
</div>
<div id="footer">Footer Text</div>
CSS
* {margin:0;padding:0;}
html, body {height: 100%;}
#wrap {min-height: 100%;}
#main {overflow:auto;
padding-bottom: 180px;} /* must be same height as the footer */
#footer {position: relative;
margin-top: -180px; /* negative value of footer height */
height: 180px;
clear:both;}
Simply add additional wrapper. At least I always do exactly that. And attach bg-image to div#no-footer, it will stretch to the bottom
html, body {
height:100%;
}
#wrap {
min-height:100%;
background-image:url(...) top left repeat-x;
}
#no-footer-pad {
padding-bottom:100px;
}
#footer {
height:100px;
margin-top:-100px;
}
html markup:
<html>
<head></head>
<body>
<div id="wrap">
<div id="no-footer-pad"></div>
</div>
<div id="footer"></div>
</body>
So you have almost this markup, you must simply add additional div (#no-footer-pad), so that your content would not overlap footer
Hey now used to position fixed for this sticky footer as like this
.footer{
position:fixed;
bottom:0;
left:0;
right:0;
height:xxxx;
}