shane.carr
11-18-2006, 12:49 PM
Hi! How do you center absolutely positioned divs? I have found two possible ways, but neither of which work as desired:
There's a way on this ancient thread (#334!) but you must know the width of the div to make it work (http://www.webdeveloper.com/forum/showthread.php?t=334)
I also discovered this way myself:
<div style="position:absolute; top:650px; width:100%;">
<div style="position:relative; margin:0 auto; text-align:center;">
this text is centered<br />
<img style="margin:0 auto;" />and so is this picture
</div>
</div>
But the horizontal scroll-bar is active, when the window's 750px wide and 2000px wide. And it stays at the same width (see attached images).
So, what's the best way to center absolutely positioned objects?
There's a way on this ancient thread (#334!) but you must know the width of the div to make it work (http://www.webdeveloper.com/forum/showthread.php?t=334)
I also discovered this way myself:
<div style="position:absolute; top:650px; width:100%;">
<div style="position:relative; margin:0 auto; text-align:center;">
this text is centered<br />
<img style="margin:0 auto;" />and so is this picture
</div>
</div>
But the horizontal scroll-bar is active, when the window's 750px wide and 2000px wide. And it stays at the same width (see attached images).
So, what's the best way to center absolutely positioned objects?