Title

Saturday, 7 February 2015

Image bigger than DIV with vertical centering


I was searching for solution for hours but can't find it.

I have div with fixed height and 50% width. And I want to display a picture inside it with 100% width and default aspect ratio but vertically centered

Sample

Thanks ;)

<div class="wrap">   <img class="img">  </div>
Answer

Add overflow:hidden to your div and then adjust the margin of the image into the negative. How much depends on the div's fixed height and the image height.

http://jsfiddle.net/willthemoor/Cu3G5/ should get you started.

No comments:

Post a Comment