PDA

View Full Version : Making a div stay at the bottom of the page (not bottom of browser window)



Hitman
21-09-2009, 04:08 PM
Hi, basically I have a div that is my footer on a page. I want it to stay at the bottom of the page, so if you have a big screen then you'll see the content, and the footer will be at the bottom and if you have a small screen you'll see the content, have to scroll down and see the footer.

The way I was doing the footer was along the lines of...



.footer {
position:absolute;
bottom: 0;
}


That makes the footer stay at the bottom of the page, which is good, but it also makes it stay at the bottom of the browser window, so if you have a small screen then it covers the content...

So I tried...



.footer {
position:static;
bottom: 0;
}


That doesn't stick to the bottom of the page or browser window - I want it to stick to the bottom of the page but not the window...

Any help, please? An example of what I want: http://ryanfait.com/ like that footer.

Homosexual
21-09-2009, 04:15 PM
position: relative; should do the trick.

jackass
21-09-2009, 04:16 PM
Doesn't 'bottom: 0;' make it go to the bottom of the broswer anyway?

You need to set an actual distance from the top of the page (for example, if your site had a height of 1000px, then set it to 1020px etc.)

Correct me if i'm wrong! :P

EDIT; Wait, ignore that, just make a container with a set height, and put the footer div inside that.

Hitman
21-09-2009, 04:32 PM
position: relative; should do the trick.Nope, does the same as static in this instance. :(


Doesn't 'bottom: 0;' make it go to the bottom of the broswer anyway?

You need to set an actual distance from the top of the page (for example, if your site had a height of 1000px, then set it to 1020px etc.)

Correct me if i'm wrong! :P

EDIT; Wait, ignore that, just make a container with a set height, and put the footer div inside that.
The thing is the height is going to change as more or less content is entered... I'll try the second suggestion in a minute. Cheers Jack, how's IMG Upload going?

Homosexual
21-09-2009, 04:40 PM
Just set the height to a specific size, e.g. 'height: 100px;'

jackass
21-09-2009, 04:42 PM
Nope, does the same as static in this instance. :(


The thing is the height is going to change as more or less content is entered... I'll try the second suggestion in a minute. Cheers Jack, how's IMG Upload going?

No problem. :)

And it's going okay thanks, but my internet has been broken the past couple of weeks, and is going to cost a LOT for it to be fixed, so it's probably going to be a while before I can finish it. :(

Hitman
21-09-2009, 05:14 PM
Just set the height to a specific size, e.g. 'height: 100px;'
The height of the footer is (didn't show full code, my bad).


No problem. :)

And it's going okay thanks, but my internet has been broken the past couple of weeks, and is going to cost a LOT for it to be fixed, so it's probably going to be a while before I can finish it. :(

Not working. :( Tried relative and static too...


.footercont {
width:100%;
position: fixed;
height:73px;
bottom: 0;
}
.footer {
background-image:url(images/footerbg.png);
background-repeat:repeat-x;
width:100%;
height:73px;
}

jackass
21-09-2009, 05:28 PM
The height of the footer is (didn't show full code, my bad).



Not working. :( Tried relative and static too...


.footercont {
width:100%;
position: fixed;
height:73px;
bottom: 0;
}
.footer {
background-image:url(images/footerbg.png);
background-repeat:repeat-x;
width:100%;
height:73px;
}



.footercont {
width:100%;
position: fixed;
height:1000px;
top: 0;
}
.footer {
background-image:url(images/footerbg.png);
background-repeat:repeat-x;
width:100%;
height:73px;
}

Try that.

As you're working from the bottom, it adds it to the bottom of the browser - upwards. ;)

Hitman
21-09-2009, 05:32 PM
.footercont {
width:100%;
position: fixed;
height:1000px;
top: 0;
}
.footer {
background-image:url(images/footerbg.png);
background-repeat:repeat-x;
width:100%;
height:73px;
}Try that.

As you're working from the bottom, it adds it to the bottom of the browser - upwards. ;)
That wont work. :P top:0 will make it stick to the top, I did test it just in case and it did. :(

AlexOC
21-09-2009, 05:41 PM
does



top: 100%;
margin-top: -100px; (half of your div height)
position: absolute;


make it stay at the bottom, in view, even if you scroll down?

like facebooks bottom bar?

MrCraig
21-09-2009, 05:42 PM
try something like this is all i can suggest



<html>
<head>
<style>
.container{
height:90%;
width:100%;
border: 1px solid black;
}
.footer{
height:10%;
width:100%;
border:1px solid red;
}
</style>
</head>
<body>
<div class="container">Main content..</div>
<div class="footer">Footer Content..</div>
</body>
</html>


I only really added the border tags for any debugging but it looks like it works, dunno if its exactly what you want though

Hitman
21-09-2009, 05:45 PM
does



top: 100%;
margin-top: -100px; (half of your div height)
position: absolute;
make it stay at the bottom, in view, even if you scroll down?

like facebooks bottom bar?I don't want it to be like facebooks bar, but what you posted looks like it'd do that.


try something like this is all i can suggest



<html>
<head>
<style>
.container{
height:90%;
width:100%;
border: 1px solid black;
}
.footer{
height:10%;
width:100%;
border:1px solid red;
}
</style>
</head>
<body>
<div class="container">Main content..</div>
<div class="footer">Footer Content..</div>
</body>
</html>
I only really added the border tags for any debugging but it looks like it works, dunno if its exactly what you want though
Now that works (for those two divs you posted)... I'll have a try at putting the content in a div and then just the footer. Cheers.

AlexOC
21-09-2009, 05:47 PM
I don't want it to be like facebooks bar, but what you posted looks like it'd do that.


Now that works (for those two divs you posted)... I'll have a try at putting the content in a div and then just the footer. Cheers.

Well it shouldnt do that, it should be at the bottom of the full page. i think.

Try it. because it positions itself below 100% of the content, then takes away half of itself to fit on.

MrCraig
21-09-2009, 05:47 PM
You MAY have to include an iframe in the container div if you want to put lots of content in it though as im not too sure what'll happen if you overfill it (but im guessing it'll stretch)

Hitman
21-09-2009, 05:51 PM
Well it shouldnt do that, it should be at the bottom of the full page. i think.

Try it. because it positions itself below 100% of the content, then takes away half of itself to fit on.Tried, does the same as the facebook bar because its position is absolute... :(


You MAY have to include an iframe in the container div if you want to put lots of content in it though as im not too sure what'll happen if you overfill it (but im guessing it'll stretch)Yeah it'll stretch.

AlexOC
21-09-2009, 06:08 PM
Tried, does the same as the facebook bar because its position is absolute... :(

Yeah it'll stretch.

Cant you change the position?

Hitman
21-09-2009, 06:11 PM
Cant you change the position?
As I said, I've tried the other positions... static, relative, fixed... they all don't do it.

Jamesy
21-09-2009, 06:11 PM
Getting a footer to stick at the bottom without going over the text is extremely difficult. HTML was never made with the same control you have over width in height :/.

Hitman
21-09-2009, 06:22 PM
Think I have it...


.footer {
background-image:url(images/footerbg.png);
background-repeat:repeat-x;
width:100%;
height:74px;
position: relative;
margin: 12em 0 0;

}

Seems to be working!

Homosexual
21-09-2009, 08:55 PM
Not to do with the question, but use shorthand for everything:



.footer {
background:url(images/footerbg.png) repeat-x;
width:100%;
height:74px;
position:relative;
margin:12em 0 0
}

Improves loading time :)

jackass
21-09-2009, 09:07 PM
Not to do with the question, but use shorthand for everything:

Improves loading time :)

Only by the smallest amount possible. :P

Homosexual
21-09-2009, 09:08 PM
But still, it helps old grannies on 56k.

jacko2244
24-09-2009, 09:08 PM
Theres a tutorial on his website. :P i looked at the site map and found one :P

Ill give you the code:



* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
height: 142px; /* .push must be the same height as .footer */
}

/*

Sticky Footer by Ryan Fait
http://ryanfait.com/

*/

and inside the layout

<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>

and the url:
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

Hope this helped!

Hitman
25-09-2009, 06:20 PM
Found that before but it never worked properly. :(

Chippiewill
26-09-2009, 12:03 AM
Not to do with the question, but use shorthand for everything:



.footer {
background:url(images/footerbg.png) repeat-x;
width:100%;
height:74px;
position:relative;
margin:12em 0 0
}
Improves loading time :)

I will thank you in 5 years time when it has saved me an entire second of my life.

Want to hide these adverts? Register an account for free!