Let's say i have six 200*200 images as flex items inside a 600px width parent div
. I want the images to be re-sized as ratio and fit in the parent without using flex-wrap.
I tried to add div
to each img
work but the structure was too long. And I found another solution work fine by adding min-width: 0;
as shown below. I don't understand how it is worked. Can someone explain it please?
HTML
<div class="stack">
<img class="test" src="http://picsum.photos/200/200" />
<img class="test" src="http://picsum.photos/200/200" />
<img class="test" src="http://picsum.photos/200/200" />
<img class="test" src="http://picsum.photos/200/200" />
<img class="test" src="http://picsum.photos/200/200" />
<img class="test" src="http://picsum.photos/200/200" />
</div>
CSS
.stack {
display: flex;
max-width: 600px;
align-items: center;
border:1px solid gold;
}
.stack img {
/* How "min-width" work in here? */
min-width: 0;
width:200px;
align-self: center;
}
I expect the width of flex items (<img>
) can be responsive to the width of its parent <div>
.