CSS Centering and Image/Div Hor & Ver

/ Published in: CSS
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.