Align a image in the center of the Div using CSS

Align a image in the center of the Div using CSS

Stack of Codes

Stack of Codes

 

HTML:
<div class="frame">
  <img src="foo"/>
</div>
CSS:

.frame { 
    height: 160px; /*can be anything*/
    width: 160px; /*can be anything*/
    position: relative;
}
img { 
    max-height: 100%; 
    max-width: 100%;
    width: auto;
    height: auto;
    position: absolute; 
    top: 0; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    margin: auto;
}

Leave a Reply

Your email address will not be published. Required fields are marked *