How can I fill the div container height with the img and also center the img?
In the example below I want the dog picture to fill the containers height, it must stay proportionate, so I dont care how wide it is.
But also I want the dog picture to be in the center of the container no matter what width the screen is.
HTML
<div class="posts">
<div class="post">
<div class="single-piece">
<a>
<img src="https://images-na.ssl-images-amazon.com/images/G/01/img15/pet-products/small-tiles/23695_pets_vertical_store_dogs_small_tile_8._CB312176604_.jpg">
</a>
</div>
</div>
<div class="post">
</div>
<div class="post">
</div>
</div>
CSS
.posts {
display: flex;
flex-flow: row wrap;
align-items: strech;
align-content: stretch;
width: 90%;
margin: 0 auto;
}
.post {
flex: 0 1 calc(33.33% - 0.666em);
height: 350px;
overflow: hidden;
border: 1px solid red;
margin-right: 1em;
}
.post:nth-child(3n) {
margin-right: -1em; //needed for codepen only
}
img {
}
See codepen below
See the Pen egQrZj by winchendonsprings (@winchendonsprings) on CodePen.