I have a container which is 100px by 100px. I have put an image in it which I don’t know the dimensions, except the fact that I have set the width to 100px. I would like to find a way in CSS to vertically align this image middle in it’s container. I have stuck overflow:hidden on the container to prevent it from showing anything outside the square.
I have found something on here on how to do the opposite (width, not height).
Wrap the image inside two divs that will mimic an html table. The outer div will have
display: tableproperty, and the inner will havedisplay: table-cellproperty. You can set thevertical-alignproperty of the inner div to be top, middle, or bottom.HTML:
CSS:
Here’s the fiddle.