1

I have this website.

I have set a footer with position fixed with a certain height and width of 100% and left:0px and bottom:0px.

The content above the footer gets blocked behind the footer when I resize the browser even though I have overflow:auto on div element above it.

Here is the screen shot when the browser is resized and the content is blocked.

https://i.sstatic.net/y4L6v.png

5
  • @J-16 SDiZ when you resize page footer doesn't cover content. Commented Aug 7, 2011 at 15:01
  • The content gets docked..when i resize browser the scroll bar does not appear.I want the scroll bar to appear. Commented Aug 7, 2011 at 15:01
  • I see this same behaviour in Chrome 13. Commented Aug 7, 2011 at 15:02
  • @Stack 101: Please see screen shot..the content gets at the back of footer making it invisible. i.imgur.com/EtQDp.png Commented Aug 7, 2011 at 15:02
  • You should probably use a different method. I suggest Ryan Fait's Sticky Footer. Commented Aug 7, 2011 at 15:12

5 Answers 5

4

You can fix this by giving your wrapper a bottom margin that is equal to to the height+padding of your footer, so in this case:

#wrapper {
    margin-bottom: 213px;
    overflow: auto;
}

The explanation is that when you position something using position:fixed, you remove it from the flow of the document in the same way as with position:absolute (the difference being that fixed will pin your content to the viewport rather than the document and so will not scroll). That means that normally positioned content is not affected by it, and acts as if it is not there.

In your case, your wrapper div was using all of the available space, which included space that was behind your footer. By adding a margin to the bottom of the wrapper, you are effectively stopping it at the start of the footer, and if more space is required a scrollbar will be displayed.

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

2 Comments

Thanks...it worked can u please explain it,i did not not understand how it worked.Thanks..!!
@Liam - I would not use padding, so that if he wanted to add a universal padding to the wrapper div, he could do so without having to consider the footer. Also, I find it makes more sense from a box model perspective, but that's just down to individual preference.
1

You probably want something like this:

<body>
  <div id="page">
    <div id="logo">...</div>
    <div id="head">...</div>
    <div id="wrapper">...</div>
    <div id="footerSpacer"></div>
    <div id="footer">...</div>
  </div>
</body>

And then the CSS file:

html, body {
    height: 100%;
}
page {
    min-height: 100%;
    position: relative;
}
footerSpacer {
    height: 200px;
}
footer {
    position: absolute;
    bottom: 0;
    height: 200px;
}

That way the footer is in the normal page flow place if the page is long. If however the page is shorter than the window height, it'll stay at the bottom of the window.

Comments

0

Do you need to have the footer position:fixed; if it's just going straight to the bottom anyways? Why not just do position:absolute;? Either that, or lower the z-index of the footer so it goes behind the content.

3 Comments

This is a bad answer. Position fixed is a way of having the footer fixed at the bottom of the screen so it scrolls with the content. When used properly position:fixed on an element can give good effects, all the OP needs to do is add margin or padding to the bottom of #wrapper equal to the total height of the footer and it is solved.
Look at the content. There really isn't any scrolling. position: absolute; would've worked perfectly fine.
Assuming the content was the same across every page of the site yes.
0

could you not put a div inbetween the body div and the footer and then add a class to it of clear:both;

Comments

-1

The image is getting docked because it has position: fixed, which glues it to that spot on the window, not that spot in the overall flow of the page. It's the same technique that people use to make those nav headers and footers that don't scroll with the page.

For what you want to do, you should float the content of your page and apply clear: both to the css of your footer, which will cause it to clear both right and left floated elements and force it to the bottom. Positioning with fixed or absolute will allow other elements to be hidden behind the footer.

Another approach would to use position: absolute instead of position: fixed to glue the footer to the bottom of the page, then wrap the main content in a <div> and give that a bottom margin equal to the height of the footer.

On another note, it is considered best practice to use lowercase characters when declaring html tags and adding attributes; I noticed you had quite a few in all uppercase. It is also usually a good idea to offload your css and javascript to external files, then import them with <link rel="stylesheet" type="text/css" src="path_to_css_file_from_html_file_location"> and <script src="path_to_javascript_file_from_html_file_location" >, respectively.

2 Comments

He wants the footer to sit a the bottom of the page even if there is no content or the content is to small.
If there is no content, the footer will be the only thing on the page and, by definition, be both at the top and the bottom. If he floats his content and tells the footer to clear it, it will sit below that content no matter how small that content is. Why was this downvoted? It is a perfectly valid solution. I even gave him some friendly tips... :/

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.