Div Layer Blues
- JimmyDallas
-
JimmyDallas
- Member since: May. 17, 2003
- Offline.
-
- Forum Stats
- Member
- Level 31
- Gamer
ok, for the longest, i been trying to figure out how to make a div layer center properly.
the short question: is there a certain setting in the CSS to make it all "perfect" (so to say)?
- Bizarro
-
Bizarro
- Member since: Dec. 6, 2002
- Offline.
-
- Forum Stats
- Member
- Level 22
- Blank Slate
there are 2 ways of doing this nicely and I happened to have stumbled upon a website explaining both the other day
one way is negative margins in which you have the give the div, position:absolute a left value of 50% and a margin-left that is negative half of the divs width.
example
the other method, which I prefer, is whatever contains the div (in most cases the body)that you want to be centered has to have text-align:center, and then the div you want centered has to have a right and left margin of auto and text-align:left to reset the alignment of the text(the text-align crap is only needed for IE5 so if you dont care about them you can leave it out)
example
- Jessii
-
Jessii
- Member since: Feb. 10, 2005
- Offline.
-
- Forum Stats
- Member
- Level 36
- Movie Buff
What I do is set
body {width:780px;}
Then I have my divs float and have my margins set so that they control where the page ends up. So say you have a top div that's 780px; wide, then you'll have the divs underneath lined up using your top div as a guide. You can take alook at my css if you want an example: http://www.fauxdreams.net/main.css

