I thought the problem was simple, but I can not centralize an image that is within div
. I have images of varying sizes and I would like to center them horizontally, but I can not use the margin: 0 auto;
property. My code:
#wrapper {
width:90%;
height:300px;
margin:0 auto;
}
#wrapper div {
width:100%;
height:100%;
overflow:hidden;
}
img {
display:block;
margin:0 auto;
}
<div id="wrapper">
<div>
<img src="http://placehold.it/900x300"/></div></div>
Yes,the"wrapper" div is required. I've been searching around and I remembered that I can use the transform
property, but would like a less "radical" solution. I also tried to put text-align:center;
in the common div and display:inline-block;
in the image, but without positive results too.