1

To try to explain my problem, I did the following code:

http://jsfiddle.net/Ridermansb/REYZ6/

The question is.

The div "Footer" should always be glued to the bottom of the screen (bottom: 0).
BUT if the div "content" grow to the point of creating a scroll bar, the div "footer" should be just below the div "content"

One should never overlap each other!

As you can see in the example, if the screen is too small the "#footer" will override "#content". This can not happen!

Thanks!

3
  • Are you wanting to have a sticky footer that always sticks to the bottom of the screen unless the content pushes it out of view? Or do you want for the content to stay the same height and have a scroll bar when the content gets to be too much? Commented May 14, 2012 at 23:49
  • I want you to push the "#footer" out when the "#content" grow. Option 1! Commented May 15, 2012 at 0:11
  • It has been over a week since I updated my answer and fixed my original bug. Does it not do something you need it to? Commented May 23, 2012 at 13:11

5 Answers 5

1

From what I understand per your fiddle, what you want to do is impossible with just css. That said, I've come up with a single line in jquery you can use to do what I think you want:

$('#spacer').height($("#footer > div").height());​

Demo

Non jquery code:

document.getElementById('spacer').style.height = document.getElementById('​​​footer-inner').offsetHeight + "px";​​​​​

Demo

Both snippets however require a slight change to your HTML structure; they both add in a spacer div that pushes up the content out from under the footer div. The second snippet however requires you give your footer's inner div an id as well.

Sign up to request clarification or add additional context in comments.

Comments

1
.container {
    position: relative;
}
.container .glued_bottom {
    position: absolute;
    bottom: 0;
    height: 20px;
}

Comments

0

few ways to tackle the footer layouts

using percentage heights can work in some cases

html, body { height:100%;}
#header {height:10%; }
#content { height:80%; }
#footer { height:10%;}

Appreciate it might not fit for the content of your site, but worth a look as css only option.

Another is the use of background css elements , color your page to be your footer color ( lets say green )

and set the header and content elements to be, say, white for eg purposes

body { background-color:green; }
#header { background-color:white; }
#content { background-color:white; }

... Couple of non Javascript ideas to play with possibly

Yes, fixed or abs positioning will cause the overlaps without adding some Javascript to keep watch and make repositioning alterations.

Hope helps a little

4 Comments

The size of the "#footer" should be fixed. I see that the only option is to use JS. Thanks.
Unless there is something I do not understand from what you are wanting, it does not require JS, and my answer should work for you.
Josh, the answer only offers a couple of css routes to try, it does not contain javascript
@Rob I was answering Riderman de Sousa Barbosa's comment on your question.
0

Via this sticky footer tutorial. The following code should be all you need to create a sticky footer.

* {
    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/

*/

In your case, you were missing pretty much all of the above css except for the 100% height on the html and body. I have updated your jsfiddle.

Live DEMO

6 Comments

The OP wanted the footer to remain in a position similar to, if not exactly the same as position: fixed;
I'll check your demo in IE and Firefox, but so far, it doesn't stay at the bottom of the screen; you have to scroll down to reach it. Tested in Chrome. Just tested it in IE and Firefox, same thing.
No, it isn't. Judging by the demo the OP offered himself, he wants the div to remain in a fixed position, but doesn't want it to overlap the content under it should it increase in size; in essence, he wants the margin of the bottom portion of the screen to be equal to if not slightly more than the height of the fixed position div.
Note, he said the footer should always be glued to the bottom of the screen unless the content pushes it down. In his example the content is longer than the screen; therefore, the footer should be pushed down. That is exactly what my demo does. The footer is pushed out of view because the content is too long. The OP will just have to be more descriptive if he really wants the help.
"#footer" is always invisible (even with the #content is small) and this should not happen. i.imgur.com/9lZBj.png He must always be aligned with "bottom: 0" on the monitor. But if the "#content" overgrow, it must push the "#footer" to just below it. i.imgur.com/WJmBD.png
|
-1

Use CSS's position:fixed; on the element with bottom and left set. e.g.:

#footer {
position: fixed;
bottom: 0px;
left: 0px;
}

1 Comment

Daedalus - it doesn't. "fixed" places the content relative to the viewport--not the block above it--as the OP is concerned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.