tags:

views:

202

answers:

6

I am trying to build this very simple (visually speaking) layout using HTML/CSS that you can see in the wire frame below:

/------------------------------------------\
|                                          |
|                header div                |
|                                          |
|------------------------------------------|
|                                       |S |
|                 main div              |C |
|                                       |R |
|                                       |O |
|                                       |L |
|                                       |L |
|                                       |  |
|                                       |B |
|                                       |A |
|                                       |R |
\------------------------------------------/

It has a 200 pixel high "header" DIV that fills 100% of the view port horizontally and then below it is the "main" DIV that fills 100% of the remaining empty space (horizontally and vertically) with scrolling set to "auto" to account for any overflowing content.

The hard part is getting the "main" DIV to fill this remaining space without using JavaScript. when I cant really use percentage heights and still have the scroll bar be entirely visible.

I guess at this point I am willing to use tables for this basic part of the layout if that becomes the only non-JS option. Semantics wont be an issue.

So how can I go about doing this? An example would be great too!

A: 

I think you can only get that behavior, barring the use of javascript that is, by setting static heights. Data won't overflow, thereby causing scrollbars, without a static height. Unless you did something with an Iframe, which I discourage just because of the added load time.

Myles
..and likely not to be indexed by search bots as part of the page. I.e. not SEO friendly.
BalusC
Well yah, but this is a CMS so semantics is a non-issue.
Bill
A: 

Just tried figuring something out and the closest pure-css solution I can find is to use percentages for both heights and setting the header's min-height to 200px. However when the viewport isn't as big as expected the bottom div goes slightly beyond the fold.

A good solution here would be to go through your statistics and figure our what the most used screen height for your visitors use is, around 800px probably. Then set something like this

#head {
      height: 25% (depending on above figure)
      min-height: 200px;
}
#body {
      height: 75%;
}

This would ensure that your design works perfectly in most cases.

Although why somebody would want to keep everything above the fold in this day and age eludes me to be honest. We've all gotten pretty well used to scrolling and with modern widescreen designs scrolling is rather ubiquitous

Swizec Teller
Wow this is a cool idea!I'm not trying to keep it above the fold just to keep it above the fold, but doing what I am doing will improve the way the UI can be used.
Bill
I guess this wont work because I need the header to be a static height.
Bill
You could still fake the header to look like it's a static height if the reservations are purely stylistic.However for a perfectly static header your only option are javascript and tables I believe.
Swizec Teller
There is no solution but your response was the best you get the big green check mark!
Bill
A: 

display: table or http://www.ironmyers.com/layouts/100%5Fpercent%5FLayouts/

glebm
A: 

Try using absolute positioning

Dmitry
A: 

I suggest you try a well tested layout like this: http://www.cssplay.co.uk/layouts/basics2.html

There you can see how it is done.

MaikL80
A: 

I just did something really similar (client work, can't show example, sorry...) You can use margins like so:

#head{
  margin-top: 0;
  margin-left: 0;
  margin-right: 0;
  height: 200px;
}

#body{
  margin: 200px 0 0 0;
  top: 200px; 
}
Moshe