tags:

views:

38

answers:

3

I have a wrapper div which is positioned absolute. Is it possible to extend the height of the wrapper div to accommodate the content and show the background color. Below the code I used:

CSS

html, body {
 width: 100%;
 height: 100%;
 margin: 0px;
 padding: 0px;
 border: 0px;
}

body {
 font-family: Arial,sans-serif;
 font-size: 2em;
 line-height: 1.5em;
}

#contentbody {
 position: absolute;
 left: 5px;
 right: 5px;
 top: 5px;
 bottom: 5px;
 background-color: Green;
}

HTML

<div id="contentbody">
 <div id="content">
  <div style="height: 1500px;">some large content</div>
 </div>
</div>
A: 

try using style = "overflow: scroll" on your DIV

EDITED: to remoe overflow: auto

Sachin Shanbhag
overflow is auto by default so i doubt it will help him with that
corroded
A: 

I don't think you should set bottom in #contentbody. By setting both top and bottom you are forcing the height of the div to be the height of the browser view-port minus 10 (top + bottom).

klausbyskov
you are probably right, but I would like to have the whole page (minus 5 pixels margin) covered by a backgroundcolor even when the content is not fullpage. how could I solve this other that using both top and bottom?
Geert
@Geert how about defining a border on the body element of the color you want, and a background color?
klausbyskov
This is perhaps the best solution, but it is still not ideal. What you want is that the DIV itself extends to the bottom minus 5 pixel margin. but I guess there is no solution for that, other than perhaps some JavaScript hacking...
Geert
A: 

Add the overflow:hidden to your html,body selector and and overflow:auto to your #contentbody div:

        html, body {
         width: 100%;
         height: 100%;
         margin: 0px;
         padding: 0px;
         border: 0px;

         overflow:hidden; /* overflow is hidden */
        }

        body {
         font-family: Arial,sans-serif;
         font-size: 2em;
         line-height: 1.5em;
        }

        #contentbody {
         position: absolute;
         left: 5px;
         right: 5px;
         top: 5px;
         bottom: 5px;
         background-color: Green;

         overflow: auto; /* overflow is auto to allow scrolling */
        }
naikus
this works for this situation, but if you have (which I do in my real script) an min-width and min-height on the #contentbody div and the browser screen is too small to show the min-width and min-height values the user is not able to see the all the content (because there are no body scrollbars)
Geert