I have this particular problem. I am loading images dynamically, and each one of them has different height. I would like the image to be positions vertically in the middle of the container. Here is how the html is structured
<div class="item">
<div class="photo">
<img />
</div>
<div class="text"></div>
</div>
Please let me know if there is a possibility to do that with either jquery or css. The height of the .photo is 140px;
Method 1: CSS Background
If
div.photohas a fixed width and height, either remove the<img />element and addstyle="background:url("http://example.com/pic.png") no-repeat scroll 50% 50%;"to the specific div, or replace the<img />element by:The image will be vertically centered now. The image will not shrink when it’s too large, though.
Method 2: CSS + HTML
See this Fiddle. The photo will be centered, and aligned vertically.
HTML:
CSS: