views:

51

answers:

4

This is probably not possible with CSS, but maybe I'm wrong:

I have a document structure like this:

BODY
  DIV[A]
    DIV[B]

DIV[A] is position:absolute with fixed with and centered on screen. It has no height setting.

DIV[B] is position:absolute with top:300px. This is the actual content DIV. Inside that, I position everything with position:absolute. Because I love position:absolute. It gives full control over positioning. No ugly text flow headaches... it's so nice.

Ok. But the problem now: DIV[B] is always only that height what I tell it to be. Now, maybe there's a cool CSS trick that would pull it always down to touch the bottom of the browser viewport?

+1  A: 

I suppose DIV[A] is your header and DIV[B] your main content div and you would like to always have your content div take all the page when there is not a lot of text in it, right?

If I remember correctly, because I can test it at the moment, you could :

html, body
{
height:100%;
}

DIV[B]
{
height:100%;
}

I think that should do the trick.

Edit: Here is a good example that might help you : http://www.xs4all.nl/~peterned/examples/csslayout1.html

Frank
Height of 100% is only considered at screen render time. Any resizing of the window will cause your layout to be undesirable.
Brad
So you're basically saying that you should keep calling a javascript function to resize the viewport
Frank
@Frank, yes, that is the only way to have a div **always** be the exact size remaining in the window.
Brad
@Brad, could you look at the link I've posted and tell me what you think about it. Try to resize the window to see what happens.
Frank
+1  A: 

To set the height to dynamically be the window height - DIV[A]'s height, you'll have to use JavaScript/jQuery and keep calling it with a SetTimeout.

Alternately, if it suits your needs, you can set DIV[B] to be position:fixed; bottom:0px;

<body onload="setupLayout();" >
...


  <script language="javascript" type="text/javascript">
    // ACTIVITIES TO RUN FOR THE PAGE
    function setupLayout() {
        setInterval('adjustLayout();', 1000);
    }

    // ADUST THE MAIN CONTAINER (content panel) LAYOUT
    function adjustLayout() {
        try {
            var divB = $get('divB');
            var divAHeight = 20px;
            divB.style.height = document.body.clientHeight - divAHeight ;
        }
        catch (e) { }
    }
  </script>
</body>
Brad
+1  A: 

when you want DIV to be a position:absolute , it should be in a position:relative Container

     <div style="position:relative" >
        <div  style="position:absolute; top:300px">
            <h3>
                Content Header</h3>
            <!--Content-->
        </div>
    </div>

so about your problem with the Div[B] , you can mix between s and s

Arrabi
What do you mean by mixing between s and s?
BugAlert
sorry,between tables and divs
Arrabi
+1  A: 
#div_to_touch_the_bottom {
   position:fixed;
   bottom:0;
   top:0;
   left:25%;
   right:25%;
} 

This DIV will touch the bottom of viewport, you can modify its left and right according to your needs. I am not sure that this the answer you are lookign for but it could be a good start

Mike