This question already has answers here:
Make footer stick to bottom of page correctly [duplicate]
(10 answers)
Closed 8 years ago.
I cannot make a footer sticky in the bottom of the page. I have read dozens of tutorials and still have a problem. In pages with contents that cover all the window, the footer is sticked in the bottom without a problem. But in pages without a lot of content, the footer is in the middle of the page.
<html><body>
text here text here
<footer id="footer">
Im in the footer and bottom of the page!
</footer>
</body></html>
body {
background: url('/static/img/bg.png');
min-width: 1300px;
height: 100%;
}
footer {
clear: both;
padding-top:20px;
padding-bottom:20px;
background-color:#222;
margin-top: 15px;
color: white;
text-align: center;
}
I have tried to add position:absolute or position:fixed and bottom:0px in the footer, but then the results are worst. There is a blank space after footer.
You can use position:fixed and bottom:0px; like this:
footer {
clear: both;
padding-top:20px;
padding-bottom:20px;
background-color:#222;
margin-top: 15px;
color: white;
text-align: center;
position:fixed;
bottom:0px;
width:100%;
}
The footer remains at the bottom no matter how much content the body has.
To remove white spaces around it and make it's width 100% you need to remove margin and padding:
body,html {
background: url('/static/img/bg.png');
width:100%;
height: 100%;
padding:0;
margin:0;
}
JSFiddle Demo
You can try this
html, body {height: 100%;}
#wrap {min-height: 100%;}
#main {overflow:auto;
padding-bottom: 150px;} /* must be same height as the footer */
#footer {position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;}
/*Opera Fix*/
body:before {
content:"";
height:100%;
float:left;
width:0;
margin-top:-32767px;/
}
This an HTML
Below is the basic structure of the HTML code. You'll notice how the footer sits outside of the wrap .
<div id="wrap">
<div id="main">
</div>
</div>
<div id="footer">
</div>
You would place your content elements inside the main . For example, if you were using a 2 column floating layout you might have this;
<div id="wrap">
<div id="main">
<div id="content">
</div>
<div id="side">
</div>
</div>
</div>
<div id="footer">
</div>
A header could be placed inside the wrap but above the main like this;
<div id="wrap">
<div id="header">
</div>
<div id="main">
</div>
</div>
<div id="footer">
</div>
Related
I am using sticky footer. I noticed that on pages where the content does not reach the bottom completely there is a small gap between the footer and the bottom of the page.
Example of short content with footer gap: http://karenrubkiewicz.com/martin/published.html
Example of long content with no footer gap: http://karenrubkiewicz.com/martin/people.html
Below is my coding.
Thanks in advance!
HTML
<div class="wrapper">
SITE CONTENT HERE
<div class="push"></div>
</div> <!-- END WRAPPER -->
<section id="footer">
<div class="left">
<li>[about]</li>
<li>[contact]</li>
<li>[pdf]</li>
<li>[Imprint]</li>
</div>
<div class="right">
<li><div class="linkedin"></div></li>
<li><div class="tumblr"></div></li>
<li><div class="behance"></div></li>
<li><div class="facebook"></div></li>
</div>
</section>
CSS
html, body{
height:100%;
}
body{
overflow-x:hidden;
}
.wrapper {
overflow-x:hidden;
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -50px; /* the bottom margin is the negative value of the footer's height */
}
#footer .push {
height: 50px; /* .push must be the same height as .footer */
}
#footer{
position: absolute;
height: 50px;
left:0;
width:100%;
min-width:1300px;
background:#000;}
You still have margin on body. You should add:
body{
margin:0;
}
I recommend you to put some css reset code. To unify common browser settings for elements (this would prevent such situation also).
I've been trying for hours now couldn't find any solution for my problem I've made my footer stick to the bottom by position:fixed;bottom:0; the footer gets to bottom but when my content is more the footer doesn't expand to the bottom relative to the content so i've did this made a container div and placed my footer in it
<div id="container">
<div id="body">
</div>
<div id="footer">
</div>
</div>
#container
{
position:relative;
}
#footer
{
position:absolute;
bottom:0;
height:30px;
}
so far so good but when i try to increase my footer size(height) to 300PX it occupies my entire page I just want the footer to be at bottom with same height i have even tried making the #body{min-height:500px;} but my footer still doesn't go down with 300px of height.
To be exact i want a footer like stackoverflow but when there is no content i should still stick to bottom with a min body height.
Hi please follow the link http://jsfiddle.net/cooolkiran/yVC8r/
<div class="page-wrap"> Content</div>
<footer class="site-footer">
I'm the Sticky Footer.
</footer>
* {
margin: 0;
}
html, body {
height: 100%;
}
.page-wrap {
min-height: 100%;
/* equal to footer height */
margin-bottom: -142px;
}
.page-wrap:after {
content: "";
display: block;
}
.site-footer, .page-wrap:after {
/* .push must be the same height as footer */
height: 142px;
}
.site-footer {
background: orange;
}
Add:
html, body {height: 100%;}
to your CSS and see if that works.
Replace -
<div id="container">
<div id="body">
</div>
<div id="footer">
</div>
</div>
with following code - (try with closing div id="body" after footer division)
<div id="container">
<div id="body">
<div id="footer">
</div>
</div>
</div>
jsfiddle - http://jsfiddle.net/nMVA5/
Try this:
<div id="container">
<div id="body">
this is body
</div>
<div id="footer">
this is footer
</div>
</div>
#container
{
border:solid red thin;
position:relative;
height:100px;
}
#footer
{
border:solid red thin;
position:absolute;
bottom:0;
height:30px;
width:100%;
}
demo link:http://jsfiddle.net/yVC8r/2/
My HTML looks like the following, without the content though as the following is only needed to answer my question:
<html>
<body>
<div class="container">
<div class="socialmedia"></div>
<div class="navbar"></div>
<div class="mainbody></div>
<div class="footer"></div>
</div>
</body>
</html>
I've been trying to get my footer to remain at the bottom of my webpage, beneath .mainbody. The problem though, is that the footer seems to sit at the bottom of my window only, not at the bottom of the webpage which could extend well below my actual window when I have a lot of content. Right now, I have all the div's above set to position "absolute"; as well the html and body are styled in the following way:
html, body{
height:100%;
margin:0;
padding:0;
}
html { background: url(/img/multiblock.png)repeat center center fixed; }
}
Now, the only way I can get my footer to remain at the bottom of the webpage is to set top:-3998px (or whatever the height of my largest window is). Obviously this won't work once a webpage has enough content on it to expand it past that height. If I set position to relative, it appears at the top of my whole webpage and when positioned absolute it appears at the bottom of the viewable window only. You can check out the website at http://www.edmuncovered.com to see what I mean or to check the rest of the code. Parts of my website include adding content every day or so so I want to make sure the webpage can increase in height with added content, but that the formatting stays the same and the footer obviously stays at the bottom. Any ideas?
I guess this is what you need...
HTML
<div id="container">
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
</div>
CSS
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
You can try something like this:
CSS:
.socialmedia, .navbar, .mainbody, .footer
{
border: 1px solid grey;
margin-top: 5px;
width: 800px;
}
.socialmedia
{
height: 20px;
}
.mainbody
{
min-height: 980px;
}
.footer
{
height: 25px;
}
Html:
<div class="container">
<div class="socialmedia">Social Media</div>
<div class="navbar">Navbar</div>
<div class="mainbody">Mainbody</div>
<div class="footer">Footer</div>
</div>
Working jsFiddle: http://jsfiddle.net/LrfXr/
I'm going to assume this is a questions similar to the one here: How to Stop Sticky Footer at Content DIV
At which there are a few good answers.
Links on that page:
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
http://twitter.github.io/bootstrap/examples/sticky-footer.html
Basically you're looking for a footer that attaches itself to the bottom of the viewport but also extends should the content push it off the viewport. Martin Bean and Ryan Fait have the best methods of this. The bootstrap's method is a variation of this method too.
Happy hunting.
Here is the jsFiddle link. Followings are your css and html code:
HTML code
<div class="container">
<div class="socialmedia">Social Media</div>
<div class="navbar">Navbar</div>
<div class="mainbody">Mainbody</br>Mainbody</br>Mainbody</br>Mainbody</div>
<div class="footer">Footer</div>
</div>
CSS
*{
margin:0;
padding:0;
}
body {
background-color:#E4E2E2;
color:#fff;
}
.container {
min-height:100%;
/*position:relative;*/
}
.socialmedia {
background-color:#186301;
padding:10px;
}
.navbar {
background:#A60206;
padding:10px;
min-height:30px;
}
.mainbody {
padding:20px;
background-color:#6D0594;
}
.footer {
position:absolute;
bottom:0;
padding:2%;
background-color:#000;
width:96%;
}
This is working for me:
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
In short, use this:
CSS
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}
HTML
<html>
<head>
<link rel="stylesheet" href="layout.css" ... />
</head>
<body>
<div class="wrapper">
<p>Your website content here.</p>
<div class="push"></div>
</div>
<div class="footer">
<p>Copyright (c) 2008</p>
</div>
</body> </html>
I have a web page that is divided into header, page and footer.
The problem is that I made the page height :auto;.
But it does not work and I need the page to automatically grow up.
This is what I have in the CSS:
/* Page */
#page-wrapper {
overflow: auto;
height: auto;
text-align: center;
}
#page {
overflow: auto;
width: 1120px;
margin: 0px auto;
padding: 50px 40px;
color: #8F8F8F;
min-height:700px;
height:auto;
}
And HTML:
<body>
<div id="banner">
<div class="img-border">
<div id="header-wrapper">
<div id="header">
<div id="logo">
</div>
</div>
</div>
</div>
</div>
<div id="wrapper">
<div id="page-wrapper">
<div id="page">
<div id="wide-content">
</div>
</div>
</div>
</div>
It is very unclear what it is that you want.
In your first line you say you want a footer, but your HTML and CSS don't show any footers.
If you want a footer which sticks to the bottom of the page, have a look at the CSS Sticky Footer.
You shouldn't need the height in there at all... a div will grow or shrink with the amount of content inside of it. Try removing height: auto; completely.
If though you mean that you want to make the content section 100% of the page height even when there isn't enough content, this should help Make div 100% height of browser window
Do you mean you want the footer of your page at the bottom and the div imbetween to take up the remaining space (it's a little difficult to determine from your wording)?
If this is you what you want, I'd suggest looking at this blog post:
http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
HTML summary:
<div id="container">
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
</div>
CSS summary:
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
I have tow pages of html that contain a footer. I want to stick the footer to the bottom of the page in both pages. It works fine when the page does not have vertical scroll but when the content is a lot and page has scroll footer stands over my contents. Here is my page layout:
<body>
<div id="container">
<div id="header"> Header </div>
<div id="menu"> Menu </div>
<div id="content"> Content </div>
<div id="footer"> Footer </div>
</div>
</body>
and here is my css:
html, body
{
width:100%;
margin:0;
}
#header, #menu, #content, #footer
{
border:thin solid #000;
}
#content
{
width:70%;
margin: 0 auto;
height:100%;
}
#footer
{
position:absolute;
bottom:0;
width:100%;
background-color:#06F;
}
Change your CSS like;
#footer{
width:100%;
background-color:#06F;
}
Here is a working Live Demo.
and if you want the footer stick to the bottom, no matter the content is, try;
#footer{
width:100%;
background-color:#06F;
bottom:0;
position: fixed;
}
But define a height to your footer and add the same amount of padding-bottom to your content, otherwise some text may be hidden by footer
Here is a working Live Demo.
#footer {background-color: #0066FF;bottom: 0;position: absolute;width: 100%;bottom:0px;}
body,html {height:100%}
by this way you will get your output
You can try this
#footer {
background-color: #0066FF;
width: 100%;
}