DIV content always have to be absolute?, DIV Content |
![]() ![]() |
DIV content always have to be absolute?, DIV Content |
Jul 24 2007, 11:34 PM
Post
#1
|
|
|
BlueTheory ![]() ![]() ![]() Group: Member Posts: 30 Joined: Jun 2006 Member No: 426,204 |
I have my div image centered because i wanted it to be centered no matter what a persons resolution is set to. But, the problem i'm running into is with the actually div content. Does both the image and content always have to be set as absolute to stay inline? Or can the conent be centered without it moving? When the image is centered and the content is absolute, you can only keep it inline with your current screen resolution. When I changed it, the image was still centered but, the content moved. Is this possible? Am I even making any sense? Please help!! Thanks a bazillion!
|
|
|
|
| *The Markster* |
Jul 25 2007, 12:59 AM
Post
#2
|
|
Guest |
The way I usually center my DIV content is by setting its "left" CSS property to 50%, then setting the appropriate "margin-left" CSS property, which can be a negative or a positive number.
So say I have a blank DIV tag that's 800px in width and 220px in height. I'd first code the DIV like usual (for this example, I'm using the class "divlayout"): CODE <div class="divlayout">empty</div> Then in my CSS, I would put: CODE <style type="text/css"> .divlayout { width: 800px; height: 220px; position: absolute; top: 150px; /* this number will vary */ left: 50%; margin-left: -400px; } </style> Notice how I set the "margin-left" property to -400 pixels. Since half of the DIV's width, 800px, is 400 and we're trying to position it correctly, it would be -400px. |
|
|
|
Jul 29 2007, 10:28 PM
Post
#3
|
|
|
BlueTheory ![]() ![]() ![]() Group: Member Posts: 30 Joined: Jun 2006 Member No: 426,204 |
thanks!
|
|
|
|
![]() ![]() |