Keeping the Footer below the lowest page content

I have a blog.
Each page has content (information articles and side panels).
Each content is of a different length down the page.

Presently, I have to repeatedly adjust the Footer so it appears below the lowest content, and then check to see if it appears well in my browser.
I know this isn’t at all efficient.

I want to use proper coding to make the Footer automatically appear below the content, irrespective of whether the content is from a long or short article or the info on the side panels.

Any thoughts?

Thanks.

  • blog-guy

Sounds to me like you’re looking for what’s called a “sticky footer”
Have a look over here http://www.sitepoint.com/forums/css-53/sticky-thread-revision-march-2010-read-before-posting-css-faq-tips-etc-171943.html#post1239966

:slight_smile:

In this case (viewing your site as you posted it in another thread), the problem is that all elements on your page are set to position: absolute.

This is not a good way to lay out page elements, because when an element is positioned absolutely, the other elements on the page basically don’t see it. It’s “out of the document flow”.

A better approach is to divide up your page into blocks of content and float them. That way they remain in the document flow and will automatically adjust their position depending on the other page elements.

In your case, you could start with three divs, one on top of the other, called, say “header”, “content” and “footer”, all set to width: 950px;

Inside “content”, then, you would have a series of divs with set width and floated left to represent the columns.

To ScallioXTX and ralph.m,

Thanks for your input.

  • blog-guy

Hi ralph.m,

Aside from the fact that every time I open my mouth I reveal just how much I don’t know, I’m confused by the above statement about an absolutely-positioned element not being “seen” by the other elements and being “out of the document flow”.

I’ve read quite a few website pages concerning positioning (I always try to do some research prior to asking anything in any forum), and quite frankly, when you come right down to it, even the most floated element is absolutely placed as per the coder’s desires. I’ve placed my elements where I want them, and they appear to be in place when viewed in IE, Chrome, and FF.

Regarding my site (and I certainly want to use the “best” coding), and regarding my over-zealous use of absolute positioning, can you tell me, specifically, where the elements aren’t being “seen” by the other elements, and are “out of the document flow”?

Aside from the annoying Footer issue, isn’t everything where it should be?

Thanks again.

It means that if one of your blocks will for some reason have a different size, it will overlap with over blocks and texts from different blocks will be drawn on each other, making whole page unreadable. Or it might cause parts of text not to be visible at all, depending on how you handle overflow.

It might happen if user has different browser defaults, non-standard fonts, small screen resolution, if you change text later or for many other reasons that you can’t foresee.

Aside from the fact that every time I open my mouth I reveal just how much I don’t know, I’m confused by the above statement about an absolutely-positioned element not being “seen” by the other elements and being “out of the document flow”.

I’ve read quite a few website pages concerning positioning (I always try to do some research prior to asking anything in any forum), and quite frankly, when you come right down to it, even the most floated element is absolutely placed as per the coder’s desires. I’ve placed my elements where I want them, and they appear to be in place when viewed in IE, Chrome, and FF.

Regarding my site (and I certainly want to use the “best” coding), and regarding my over-zealous use of absolute positioning, can you tell me, specifically, where the elements aren’t being “seen” by the other elements, and are “out of the document flow”?

When you turn CSS off, you’ll see the “document flow”. The elements who come first in source push down the ones who come afterwards. With CSS off, you’ll see plain ugly text who never overlaps each other, because they “see” each other, and follow the ideas in Flatland: in a 2-dimensional world, if two elements cannot occupy the same space at the same time (just like in our world), then one has to push the other out of the way. And they generally act like soap bubbles: they’re all trying to be as close to the top left corner as possible (top right corner if you’re doing arabic or hebrew page). Remove an element from the top, and the next one down will slide up to take its place.

When you have CSS on, you’re able to introduce the third dimension: depth. You can “pull” things over each other or just pick them up and tack them “on top of” other things, like setting one piece of paper over another. When you start doing this, you start disrupting the “document flow” (those set of inherent rules that forces elements to keep each other from overlapping each other because there is no 3rd dimension).

This isn’t a bad thing: disrupting the flow is how we create layouts.

But using absolute positioning to do it is (usually) going overboard, and creates very brittle pages (as you’ve seen: you have different amounts of content on each page, and the elements are rigidly staying exactly where you’ve placed them; they can’t adjust). Before anyone mentions it, yes, there are designers who’ve done “flowing” pages with all abso-po (andy clarke), but those are pretty much design experiments, not something most people would consciously use in the real world.

Floats are more complicated than simple 2-D document flow vs absolute positioning, but once you understand them, you’ll see why “good” pages can use floats without having to position them manually (if you see “position: relative” on a floated box, they’re usually not using that to place it on the page… positioning comes with other goodies we use).

The only reasonable way to let your content boxes push your footer down is to NOT position them manually.

Looking at your site, I think the first thing you want to do right now is give each of your main boxes some ugly background colours. This will show you what you’re doing in its full hideous glory. It’ll show you that your footer isn’t the only one having problems. The whole page is.

When you see the text overflowing out of your “panel” divs, you’ll see another danger in your code: setting explicit heights on elements. When designers write with the “flow” in mind, we also (generally) let the content set the heights of their boxes… again, so that those boxes can push the stuff below them further down.

How I would have written your page:
Everything you see in the top, down to the menu and the icons, I’d put in the box called #header. That whole thing looks like a header and header-type info. If you want to still manually position the stuff inside the #header for now, give #header “position: relative” which means when you absolutely position all the stuff inside it, they’ll all see #header’s top left corner as their reference for 0,0.

Then the middle part, I’d make one big box called #main or something. Inside #main would be each of your columns, which would be floated and with a set width. You won’t need to set a height on them, they’ll get stretched out by the text inside them. Most of them can have the same width, though you’d probably want a class on the first one to make it wider than the others. The rest don’t really need any classes or id’s:

#main div {
float: left;
width: whatever (i’d set it in em’s myself, but for now try pixels if you’re more comfortable with that)
}
#main .aboutme {
width: something wider;
}

I said floats were totally different and stranger than absolutely positioned boxes. They’re kind like Post-It notes: they’re attached to their container (#main) at the top, but they kind stick up towards you, so they’re not stretching their container as tall as they are. So we use technique to make the static box container (#main) to enclose its floats (tell #main it has floated children so that it will enclose them like it would with any non-floated children, regular document-flow stuff).

IE has bugs. One of them is something called HasLayout… which you can read about here. But simply, if you give #main a width, IE will make it enclose its floats.

For everyone else (and IE8 and 9): you can add this CSS


#main:after {
  content: " "; /*we're creating "text" as a last-child of #main, which here is just a space*/
  display: block; /*we make it a block element*/
  clear: both; /*only blocks can clear floats*/
  height: 0; /*just in case some browser shows the space*/
}

Now we’ve made a “non-floated child” inside #main and while #main won’t “see” the floats, it’ll “see” the non-float we’ve just added… and has to enclose it, so now the bottom of #main is the same as the bottoms of the floats inside.

Now for extra certainty, #footer will clear the floats as well:
#footer {
clear: both;
}

Since floats break the flow for block elements, those block elements have to “clear” the floats in order to be pushed down by them. Which is good enough for the rest of us.

If you’re interested in seeing people use margins and floats instead of absolute positioning to make page layouts, this book is old enough that it might be in your local library:
HTML Utopia: Designing Without Tables Using CSS by Rachel Andrews and Dan Shafer. Yeah, it’s a SitePoint book, but I’m plugging it because it’s the book that showed me really how to make layouts with CSS. It’s a beginner’s book and does NOT get into the real rules of floats, which is why the examples should look like pants in IE6 and 7, but it gets you started in a sane manner.

To CyberAlien and Stomme poes,

A wealth of information… thank you, thank you, thank you for your input.

dumb blog-guy :frowning:

Stupid me… you have nothing you need to “stick out” of your middle section… I believe Crusty used the way-easier method of enclosing floats in his rewrite (which is excellent btw): overflow: hidden on #main will also make the #main box “see” its floats. Since it had to know what’s (possibly) overflowing in order to deal with overflow (either hiding it or whatever you tell it), it has to “see” its content… and when a static box sees its content inside, it encloses it. So enclosing floats is overflow’s moonlight job : )

It’s usually the first thing you want to use. The :after method I listed above is really only for when you can’t let overflow get hidden or you don’t want scrollbars on that box (overflow: auto also works to enclose floats, but if someone does try to overflow out, scrollbars are created).

dumb blog-guy

You think we learned all this stuff in a day? Took me 3 years.