View Full Version : READ if you have a problem alligning Div layers


emeraldice
04-23-2004, 10:32 PM
hey guys, i was wondering about this all day.
if you have your background centered so that when you adjust your window it'll stay in the center, with

background-position: 50% 0%;

but your div layers are positioned by absolute pixeling, so that when you adjust your window your background moves but not your divs,
i found the solution!!!!!!

I cant take all the credit, because when i was having trouble Calidris gave me this :

<div style="position: relative; left: 50%; margin-left: 100px; width: 200px;">

but there was some weirdness about the margins and the width, so i changed it around and...

<div id=layer1 style="position: relative; left: 50%; top: 60%; width: 340px; z-index:1;">

just change the left and top percents around a little until u get there u want it, o and of course u can change the width, thats just whats on my page. but yeh now no matter how you adjust your page everything stays smooth!

isnt it great? :D

Calidris
04-23-2004, 11:25 PM
You left out the vital bit! lol

The style I posted centers the div, but ONLY if the "margin-left" of the element is exactly half of the "left" of the element. Here's examples to explain:

<div style="position: relative; left: 50%; margin-left: 100px; width: 200px;">
<div style="position: relative; left: 50%; margin-left: 200px; width: 400px;">
<div style="position: relative; left: 50%; margin-left: 375px; width: 750px;">

All of these elements will align to the center of the screen.

Also: a link to My original post (http://www.lissaexplains.com/forum/showthread.php?t=53737) about this