You can align an image vertically center inside a <div> by using the CSS vertical-align property in combination with the display: table-cell; on the containing div element.
Additionally, since CSS margin property is not applicable to display: table-cell; elements, so we've wrapped the containing DIV with another DIV (.outer-wrapper) and applied margin on it. This solution will work even for images with greater height than containing DIV.
Use the CSS
vertical-alignPropertyYou can align an image vertically center inside a
<div>by using the CSSvertical-alignproperty in combination with thedisplay: table-cell;on the containing div element.Additionally, since CSS
marginproperty is not applicable todisplay: table-cell;elements, so we've wrapped the containing DIV with another DIV (.outer-wrapper) and applied margin on it. This solution will work even for images with greater height than containing DIV.You can also use the CSS positioning method to vertically align an image inside a DIV.
Let's take a look at an example to understand how it basically works:
need an explanation for this answer? contact us directly to get an explanation for this answer