Log in

View Full Version : Positioning problem.



shachi
08-13-2006, 10:04 AM
Hello all,
I was trying to position a div vertically and horizontally in the center(in all resolutions) but unfortunately due to some reason the div gets far too much to the right even when I place the left positioning 50%.

My code so far is something like this:



<div id="test" style="position:absolute;left:50%;top:50%;height:300px;width:500px;border:1px solid;"></div>


Are there any hacks or tips for this problem?? Any help would be greatly appreciated. Thanks in advance.

ItsMeOnly
08-13-2006, 10:22 AM
do not position horizontally:, use margin-left: auto; margin-right: auto,
the 50% says it should be PLACED starting from 50%, not centered.

ItsMeOnly
08-13-2006, 10:23 AM
also, parent ought to have text-align: center.

shachi
08-15-2006, 05:35 PM
I meant centering vertically as well as horizontally.

ItsMeOnly
08-15-2006, 05:54 PM
The example I provided is for horizontal centering- for vertical centering there are several methods, and probably none will work for document body as it won't have height defined- I guess you just need to stick with 50% for vertical (top).

shachi
08-16-2006, 05:45 AM
Ok thanks for your help anyways.:)