Forum Moderators: not2easy

Message Too Old, No Replies

How to make div layer center of a page

         

jimijoe

1:20 am on Feb 10, 2007 (gmt 0)

10+ Year Member



Please let me know how to make a div layer center of a page which it works with any screen 800x600, 1024x768, ...etc.

<DIV style="width: 154; position: absolute; bottom: 0; height: 60; left: 12; top: 0" #0000FF"><b><font color="#0000FF"><font size="7">ABCD</font>&nbsp;</font></b>
</DIV>

Thanks,

supermanjnk

7:23 am on Feb 10, 2007 (gmt 0)

10+ Year Member



If a width is set adding:
margin-left:auto;
margin-right:auto;
to the item should center it (assuming a proper doctype)

mihai2u

3:33 am on Feb 11, 2007 (gmt 0)

10+ Year Member



Centering horizontaly AND verticaly:

#outerdiv {position:absolute;top:50%;left:50%;overflow:show;}
#innerdiv {position:absolute;top:-(50% of your height);left:-(50% of your width);}.. i.e. top:-30px;left:-77px;

<div id="outerdiv">
<div id="innerdiv">
<p>Hello world</p>
</div>
</div>

Hope you don't want to use inline styles!

jimijoe

9:26 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



Thank you all.

Robin_reala

11:27 pm on Feb 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remember that you’ll need to use an unit in your CSS values (in this case probably ‘px’) unless they’re 0.