Posted By

fadehelix on 02/01/11


Tagged

css center


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

saman
tmbrenneke


Center div in another div


 / Published in: CSS
 

  1. #wrapper {
  2. position:relative;
  3. }
  4. #centeredBox {
  5. position:absolute;
  6. top: 50%;
  7. left: 50%;
  8. width:200px;
  9. height:300px;
  10. margin-left: -100px; /*1/2 width*/
  11. margin-top: -150px; /*1/2 of height*/
  12. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: maltem on February 1, 2011

why not

centeredBox {width:200px;height:300px;margin:auto;}

?

Posted By: fadehelix on February 6, 2011

because margin:auto works only for horizontal positioning

You need to login to post a comment.