I need to center an image in a middle of a div.
<div class="main">
<img...>
</div>
In the example below the image is centered, but not in the middle.
I need to center an image in a middle of a div.
<div class="main">
<img...>
</div>
In the example below the image is centered, but not in the middle.
You can use
display: flex;
DEMO
Simple and easy method to do this,
You can use the simplest way -> display: table-cell; which allows you to use vertical-align attribute
Cleanest solution would be to make your div
display:flex
and align/justify content to center.Your updated Fiddle: https://jsfiddle.net/y9j21ocr/1/
More reads on flexbox (recommended)
To vertically center your div, you can use positioning. Just apply
to your image, and it will be vertically centered.
It is really easy if you can give image as background to div
If you dont want to use inline style you can do