Posted By

iqwebdev on 07/14/10


Tagged

image centering


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

seloh77
bogastyle


CSS Centering an Image (Vertical & Horizontal)


 / Published in: CSS
 

  1. // CSS background-image Technique:
  2.  
  3. html {
  4. width:100%;
  5. height:100%;
  6. background:url(logo.png) center center no-repeat;
  7. }
  8.  
  9.  
  10. // CSS + Inline Image Technique:
  11.  
  12. img {
  13. position: absolute;
  14. top: 50%;
  15. left: 50%;
  16. width: 500px;
  17. height: 500px;
  18. margin-top: -250px; /* Half the height */
  19. margin-left: -250px; /* Half the width */
  20. }

Report this snippet  

You need to login to post a comment.