tags:

views:

326

answers:

3

I have a site which always has a height of 100%. The header and the footer always has a fixed height. First some code:

CSS

#header { height: 50px; }
#footer { position: absolute; bottom: 0px; height: 20px; }

HTML

<!-- in the body tag -->
<div id="header">Header</div>
<div id="content-Left"></div>
<div id="content-Right"></div>
<div id="footer"></div>

EDIT: As you can see I have a div content(left and right) between header and footer. I want these divs to fill up all the space between header and footer. The content-left div must always show a right-border from header to footer. How can I do this?

A: 

i suggest to solve it like that:

#header {
       position: fixed;
       top: 0px;
       left: 0px;
       width: 100%;
       height: 50px;
       }

#footer {
       position: fixed;
       bottom: 0px;
       left: 0px;
       width: 100%;
       height: 20px;
       }

#content-Left {
       position: fixed;
       top: 50px; /* Close to the Header */
       bottom: 20px; /* Scales the Div down upon the Footer */
       left: 0px; /* Position it to the left */
       width: 50%;
       overflow: auto; /* Makes the Content scrollable if its required */
       border-right: 1px solid #000000;
       /* Border as required - just change size,type and color as you want */
       }

#content-Right {
       position: fixed;
       top: 50px; /* Close to the Header */
       right: 0px; /* Position it to the right */
       bottom: 20px; /* Scales the Div down upon the Footer */
       width: 50%;
       overflow: auto; /* Makes the Content scrollable if its required */
       }
snuffer.ch
I've edited my post. I don't want my page to scroll. The content-right div will have an overflow.
Martijn
above please find my edited css-code. this solution does simulate a "frame"-layout. I personally do not recommend to create a layout like that due to the content invisibilty when the user change the window size.
snuffer.ch
Yes that's another aspect I have to tackle. How would you avoid this problem but still keeps concept?
Martijn
that depends on the matter of the project - whats the reason to always see the header and the footer? why no scrolling if the content would force to scroll? that layout has a lot of tackles depending on the window-size and users desctop resolution.
snuffer.ch
I am developing more of a application instead of a website. And for this reason I want the header and footer to be visible
Martijn
ok - the header and footer visibility is clear now for me. but if you add the "overflow: auto;" tag to the content-div's you can handle the screen resolution issue.
snuffer.ch
Thnx, this is exactly what I want :) Can you tell me why the space between header and footer is filled now?
Martijn
i just improved the formatting and added some comments to explain why the content is filling the complete space between header and footer
snuffer.ch
Thnx for the explanation. Can i say that position: fixed in combination with bottom: Npx fills the remaing space between (in this case) the header and footer. If so, why doesn't position: absolute do this?
Martijn
position absolute would have the same effect. but if you use the absolute effect and any element outside your current classes would be bigger than the current screen you would loose the fixed layer positions. you can simulate that effect if you add some <br />'s just before the body-end-tag. and you'll see the differences between absolute and fixed. Is that your accepted solution? or do you need any further information?
snuffer.ch
Thnx. One last question. If you use position absolute or fixed and set the top and bottom, all the space between top and bottom will be occupied? And when using position: absolute/fixed you always should also set the top, left and bottom? Thanks again
Martijn
its as you would draw a rectangle and you define the position of your top-line, the right- and/or left- sideline, as well as the bottom line. best way to learn it is playing around :-) good luck
snuffer.ch
That's a nice explanation. Thnx!
Martijn
A: 

You can use fixed positioning BUT:

  • you'll have totally different sizes of your areas depending on screen resp. window size of the user
  • you'll have no scrolling, whatever your content does
  • it won't work in IE6

There might be some usage cases for fixed positioning, I for my part haven't seen any so far.

In order to avoid layout distortion in different browsers I would solve this with floats. Meaning I would put the left and right divisions into a content_wrapper and then float the two content divisions to the left resp. to the right of the wrapper.

<div header />
<div content wrapper>
    <div left float:left />
    <div right float:right />
</div>
<div footer />

This also enables you to avoid margins on the content divisions and use them on the wrapper if needed.

tharkun
A: 

Fixed footer, without javascript, right?

Wrap everything in <div id="container"></div>. In your CSS:

*, body {margin: 0; padding: 0;} 
#container {display: block; position: absolute; min-height: 100%;} 
#content-Left {border-right: 1px solid #000; } 
#footer {position: absolute; display: block; bottom: 0; height: 3em }

If you have an IE6 stylesheet already, add this:

body, #container {height: 100%;}

If not, create one or else add this to the head of your HTML documents:

<!--[if lt IE 7]> <style>body, #container {height: 100%;}</style> <![endif]-->

Should do the trick.

Jason Rhodes