I have a flexbox with a couple of flexbox items which have a width of about 50%. A flexbox item either contains one or more <p>
elements or a single <img />
.
The flexbox items with an image should be completely filled with the image, without it being set as the background of the surounding div.The images always seem to have a small red bar below, even if the image fills the entire width. How can I make the image fill the entire flexbox item?
It does not matter if the aspect ratio of the image changes.
I don't just want the empty space below the image gone. I want it to strech out to use the full width of the flexbox item as well. So it fills the flexbox item.
.container {
width: 500px;
}
.flexbox {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.flex-item {
border: 1px solid black;
background: red;
margin: 25px 0;
width: 47%;
flex-basis: 47%;
}
img {
max-width: 100%;
background: white;
}
<div class="container flexbox">
<div class="flex-item">
<p>It should work with a big image</p>
</div>
<div class="flex-item">
<img src="http://goo.gl/6EO4mj" />
</div>
<div class="flex-item">
<p>But also with a small one</p>
</div>
<div class="flex-item">
<img src="http://goo.gl/nxXSMO" />
</div>
<div>
EDIT: Added emphasis. Added more explaination.