Posted By

iqwebdev on 07/14/10


Tagged

centering


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

seloh77
joacoleo
kubaitis


CSS Centering and Image/Div Hor & Ver


 / Published in: CSS
 

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.

  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. }

Report this snippet  

You need to login to post a comment.