Center a DIV which is in a absolutely positioned DIV

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

Basically I have this:

Code:
<div id="div1">
   <div id="div2">
   </div>
</div>

Code:
#div1{height:100%;width:100%;position:absolute;bottom:0;right:0}
#div2{background:#fff;width:600px;height:600px}

Basically, I want to horizontally center DIV2, and vertically if possible.

....bit out of the loop with xhtml/css atm....is it possible?

Thanks.

EDIT:

Before you say it:

Code:
margin{0 auto}

...doesn't work in IE.
 
Last edited:
that's all the CSS that there is......I have isolated the issue to that....I am just mucking around atm with an idea.....so there isn't actually a "site" yet....

Managed to come up with a temp solution, but I am unsure as to where it works in IE6 which is important to me.......

Code:
#div1{height:100%;width:100%;position:absolute;bottom:0;right:0;text-align:center}
#div2{background:#fff;width:600px;height:600px;marign:25px auto}

....doesn't do vertical aligning, but will do if it works in ie6.

The margin:0 auto does firefox, and the text-align:center does IE.
 
#div1{height:100%;width:100%;position:relative;bottom:0;right:0}

.div2 {width:600px; position:absolute; left:50%; margin-left:-250px;
}

though

.div2 {margin: Zpx auto; }
Should work :(
 
did you see my post before.....confirmed that it works (my code) in IE6, firefox, IE7 + Opera....

See my original post for why margin:0 auto; was good on its own (if you missed it)....

EDIT:

Your solution doesn't work on all resolution screens im afraid :(

EDIT AGAIN:

Thanks for the effort though :) mucho appreciated.
 
Last edited:
Forgot to say what i was working on (incase you were interested)....

....working on a purely html/css litebox implementation....obviously limited, but I just wanted something that wasn't as big as lightbox for a couple of images.
 
Didn't work quite how I expected, but you can see it in action here:

Its slow cause its a free host, i feel that if I had a faster host, it would be faster:

linky!

user browser only has to load ~1KB of extra html/css/images rather than the 70KB+ for lightbox, so its decent if you only need to show off a few images.

EDIT:

Works now....
 
Last edited:
Back
Top Bottom