Anyone who can tell me how to vertically align an image in a DIV without a fixed height for the container DIV? With a fixed height I can do this:
HTML
<div class="views-field-field-thumbs-accessories">
<div class="sensorimage">
<a href="/accessory/bag-15">
<img width="120" height="120" title="Bag" alt="Bag" src="http://localhost/sites/default/files/thumbs/bag.jpg" typeof="foaf:Image">
</a>
</div>
</div>
CSS
.sensorimage {
height: 100px; /* max-height does not work*/
min-width:190px;
position: relative;
margin-bottom:10px;
}
.sensorimage img {
max-height: 100%;
width:auto;
position: absolute;
top: 0;
bottom: 0;
margin-bottom: auto;
margin-top: auto;
}
This gives me almost what I want. The images are vertically centered in the DIV. But since the DIV with the class .sensorimage
must have a fixed height, certain images appears too small. I want the images to have their natural height and width. I have tried with "max-height" but that hides all images for some reason. I have also tried to fiddle with display:table
for the outer div and display:table-cell
and vertical-align:middle
for the image (or the inner div), with no luck.
Anyone?
Edited: for ex. if 2 images are 30 px high and one image in the same row is 100 px high, the smaller images should still be vertically centered.