My goal is to use flex
to easily center an img
vertically inside a div
, however, the behavior differs across various browsers.
.flex-container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
justify-content: flex-start;
}
.flex-item {
height: 222px;
width: 200px;
border: 1px solid lightgray;
padding: 5px;
margin: 5px;
}
.flex-item img {
max-width: 100%;
max-height: 100%;
align-self: center;
-webkit-align-self: center;
margin: auto;
}
.item-image {
border: 1px solid lightgray;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
width: 190px;
height: 120px;
}
<div class="flex-container">
<div class="flex-item">
<div class="item-image">
<img src="https://c1.staticflickr.com/9/8264/8700922582_d7b50280b4_z.jpg">
</div>
</div>
</div>
https://jsfiddle.net/e0m2d6hx/
In Chrome, it works well, but in IE and FF, there seems to be an issue with max-width
.
Could someone assist me with this? I am aware that I can center the img
without using flex
, but I would like to understand this approach better.