views:

256

answers:

5

I am having a bit of difficulties with the page below. It's ALMOST working correctly.

The red box should be centered (h&v) on the window. WORKS.

The yellow box should be affixed to the bottom of the window. WORKS.

When the window is less then 400 pixels high scroll bars should appear and the yellow box should appear at the bottom of the scroll area. Basically I never want the yellow box to appear over the red box, or vice-versa. DOESN'T WORK

Anyone know how I can achieve this?

http://tinyurl.com/odhzbg

Thanks.

+1  A: 
#footer{z-index: 1000;}
#logo{z-index: 1001;}
Time Machine
Never want them to be occupy the same space. The footer should be below the logo if the viewport is made smaller then available area.
Louis W
A: 

z-index is what you need. although 1000 is a bit excessive a simple

#footer{ z-index:2; }
#logo{ z-index:3; }

would do the trick

corymathews
A: 

It's useful to remember that, without specifying z-index, the elements stack up with the latest element 'highest' in the z-order. So, if you wanted to avoid specifying z-index, reverse the html:

<body>


    <div id="wrapper">

     <div id="footer">

      This is the footer. It should always appear at the bottom of the page, but not over the red box.   

     </div>

     <div id="logo">
      <h1>Logo</h1>
     </div>

    </div>

</body>

Otherwise, as the other answer suggest, specifying a greater number for the #logo than for the #footer will cause #logo to be higher.

To enforce scrollbars when the view-port window is < 400px,

#wrapper {
min-width: 400px;
min-height: 400px;
overflow: scroll; /* or overflow: auto */
}
David Thomas
As previously stated, changing the z-index will just make the logo appear over the footer. I do not want them to overlap at all. If the viewport is resized to have a height shorter then the two items combined it should show scrollbars and have the footer stacked below the logo.
Louis W
overflow: scroll will always display scrollbars whereas auto will detect if scrollbars are necessary (as you probably know), but just clarifying.
Tres
+1  A: 

Add this to the CSS for #wrapper:

height: 100%;
position: relative;

The reason this works is because your absolutely positioned elements are positioned relative to the viewport due to the absence of any other containing block. By adding position: relative to the #wrapper (or the body for that matter) you make sure that the containing block becomes the entire body content instead.

The height: 100% is then only needed to ensure that the containing block does at least reach the bottom of the viewport.

mercator
Bingo, this works as intended. Thank you. Doesn't work in IE6, but I don't think that's a huge issue here, if so I can add the min-height hack.
Louis W
And actually, do you need the wrapper for anything else? Because given all your current CSS, the `#wrapper` is unnecessary. You could just move all its properties (including the above) to the `body`.
mercator
A: 

Z-Index is not a factor here. Z-Index will still allow the elements to overlap - it will only dictate which element is on top.

Use a floating element after the red div in the document flow, and then the use of clear on the yellow to create a relationship between the elements (i.e. the yellow div will clear the red and will not overlap).

Sandwiching a relatively-sized element (e.g. height: 100%) between the two will push the yellow div to the bottom of the screen, but it may be tricky to vertically align properly.

jscharf