Horizontal-Vertical div align


 / Published in: CSS
 

  1. #mydiv {
  2. position:absolute;
  3. top: 50%;
  4. left: 50%;
  5. width:350px;
  6. height:300px;
  7. margin-top: -150px; /*set to a negative number 1/2 of your height*/
  8. margin-left: -175px; /*set to a negative number 1/2 of your width*/
  9. border: 2px solid #2982C6;
  10. background-color: #FFF;
  11. text-align: center;
  12. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: soren121 on June 2, 2009

Excellent snipplet, works great if you need to center a non-expanding div like a login form.

Posted By: jakclark on March 19, 2011

Brilliant, a very late comment, but worked for me - so I thought I'd say my thanks :') - Jak Clark www.jakclarkdesign.co.uk

You need to login to post a comment.