views:

130

answers:

4

for my web application, i would like the main div to be full screen (both width and height = 100%), and regardless of content, i want it to stay at that size. that means, if there are not much content, it shouldn't shrink, and if there are too much content, it shouldn't push this main div.

how can i do this?

(i'm ok with hacks applied to this div, as long as it will keep contents hack-free)

A: 

Use the HTML

<div id="full-size">
    <div id="wrapper">
        Your content goes here.
    </div>
</div>

and use the CSS:

html, body {margin:0;padding:0;height:100%;}
#full-size {
    height:100%;
    width:100%;
    position:absolute;
    top:0;
    left:0;
    overflow:hidden;
}
#wrapper {
    /*You can add padding and margins here.*/
    padding:0;
    margin:0;
}

Make sure that the HTML is in the root element.

Hope this helps!

mattbasta
You will need some javascript to make maximize the browser window.
Byron Whitlock
thanks, this works ok, except one problem:- if an element is pushing wrapper (because it has 100% height), wrapper's height exceeds screen, results in overflow. if i remove 100% height from element, then it doesn't fill wrapper.
throwaway007
@throwaway007: I've updated the code. Check it out now!
mattbasta
@Byron: That's untrue. JS is entirely unnecessary for this. The only browser that might now work 100% is IE6, and that would be a case-by-case thing.
mattbasta
A: 

Or even just:

<div id="full-size">
  Your contents go here
</div>
html,body{ margin:0; padding:0; height:100%; width:100%; }
#full-size{
  height:100%;
  width:100%;
  overflow:hidden; /* or overflow:auto; if you want scrollbars */
}

(html, body can be set to like.. 95%-99% or some such to account for slight inconsistencies in margins, etc.)

lucideer
A: 
<html>
<div style="width:100%; height:100%; position:fixed; left:0;top:0;overflow:hidden;">

</div>
</html>
Bob
A: 
#fullDiv {
  position: absolute;
  margin: 0;
  padding: 0;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  overflow: hidden; /* or auto or scroll */
}
Robusto
The `right:0` and `bottom:0` descriptors are unnecessary; they will override the `top` and `left` descriptors. This used to get me all the time; CSS isn't like Windows Forms or XAML in this respect.
mattbasta
@mattbasta: Better check your work again then. I use this in FF 3.6, Safari and IE and it works great in all three. It's how I make a transparent "shield window" for modal popin dialogs.
Robusto
@mattbasta: Oh, and forgot to mention Chrome and Opera.
Robusto
@Robusto: It may work, but those descriptors are unnecessary if you set the width and height properly
mattbasta
@mattbasta: You stated that the right:0 and bottom:0 descriptors will override top and left. That is incorrect. What will not work is the 100% width and 100% height, esp. if you have borders and/or padding (and cross-browser implementations). What I have shown has been what I have been relying on for years without a problem, and the only way I have found to guarantee that the styling objective will be achieved in all cases.
Robusto