Posted By

JimSangwine on 05/05/11


Tagged


Versions (?)

Exactly Center an Image/Div Horizontally and Vertically


 / Published in: CSS
 

  1. .center {
  2. width: 300px;
  3. height: 300px;
  4. position: absolute;
  5. left: 50%;
  6. top: 50%;
  7. margin-left: -150px;
  8. margin-top: -150px;
  9. }
  10.  
  11. /* Negative margins are exactly half the height and width, which pull the element back into perfect center. Only works with elements of a fixed height/width. */

Report this snippet  

You need to login to post a comment.