tags:

views:

228

answers:

2

I'm new to doing layouts with CSS (I haven't done any web design for a long long time) and I can't seem to figure out how to get the footer of the page to display at the bottom the way I want.

Requirements: -Display at bottom of content if content exceeds vertical size of viewport -Display at bottom of viewport if viewport exceeds vertical size of content.

The code that I am using sets the footer at the bottom of the viewport, but if I size the browser to be shorter than the content, it just covers the content.

Code: <div style="background-image:url(footer_bg.jpg); background-position:bottom; background-repeat:repeat-x; height:235px; width:100%; bottom:0px; position:absolute;"></div>

My main goal is to have a footer with text (ie. company info, contact info) and a background gradient. I'd like the footer background to span the width of the page, but I don't know if I can do that with the 960 gs divs.

EDIT: I'd like to do this with all CSS, no scripts if possible.
I found some good code to get a CSS footer at this link:
http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page

The main problem I'm experiencing right now in implementing that with 960gs is the float:left; in the 960gs CSS. It seems that it's preventing my grids from vertically expanding the parent <div>. However, if I remove the float, 960gs seems to not work as well.

The following is the link with the float removed. The 'a' column is a grid_7 suffix_1 and the 'b' column should be grid_4 in the same container_12. In other words, they should be right next to each other.

A: 

In CSS, there is no "if/else" ability. This is where scripting languages come in.

Look up JQuery. In JQuery, you can grab an element with the #id footer and say something like:

$('#footer').addClass('bottomView');

'bottomView' could make it so that element with the id footer sticks to the bottom of the viewport. Then, when the user scrolls, which JQuery can monitor, it can check to see if it wants to change the class to 'bottomContent'.

Then in your css, just have classes bottomView and bottomContent that place the element where you want.

Good luck.

DexterW
I'd like to try to avoid scripts. If possible, I want to do it with all CSS. Will add comment to original question for some clarification.
Nick
A: 

Have a look at CSS Sticky Footer. It is done in pure html/css with no scripting at all. There is an explanation of how to get it to work with 960gs at signalkraft.com.

Hope this helps.

Excellent. This worked for me. The only things I could see that were different from solutions that I tried before were the `overflow` and the `clear`. I think it is probably the `clear:both;` that did the trick. Thanks.
Nick