I'm attempting to build a very simple CSS flex image gallery that shrinks the width of the images depending on the size of the container:
HTML:
<div class="grid-container">
<div class="grid-item">
<img src="small-thumb-dpi.jpg" />
<div>this is the item description</div>
</div>
...(more items here)
</div>
CSS:
.grid-container {
display: flex;
flex-flow: row wrap;
}
The problem I have is maybe because I'm using "flex: 1 1 auto;" for the gallery items, like so:
.grid-item {
flex: 1 1 auto;
width: 236px;
margin: .35vw;
}
The code above creates the flex grid I'm looking for except the images on the last row expand to fill the available space, like:
Here is my code:
body {
margin: 0;
padding: 10px;
}
.grid-container {
display: flex;
flex-flow: row wrap;
}
.grid-item {
background-color: lightgray;
flex: 1 1 auto;
width: 300px;
margin: .45vw;
padding: 10px;
box-sizing: border-box;
}
.grid-container img {
width: 100%;
height: auto;
}
<div class="grid-container">
<div class="grid-item">
<img src="https://pbs.twimg.com/media/CZsY7k0WAAA_sk5.jpg" />
<div classs=item-description>This is the item description</div>
</div>
<div class="grid-item">
<img src="https://pbs.twimg.com/media/CZsY7k0WAAA_sk5.jpg" />
<div classs=item-description>This is the item description</div>
</div>
<div class="grid-item">
<img src="https://pbs.twimg.com/media/CZsY7k0WAAA_sk5.jpg" />
<div classs=item-description>This is the item description</div>
</div>
<div class="grid-item">
<img src="https://pbs.twimg.com/media/CZsY7k0WAAA_sk5.jpg" />
<div classs=item-description>This is the item description</div>
</div>
<div class="grid-item">
<img src="https://pbs.twimg.com/media/CZsY7k0WAAA_sk5.jpg" />
<div classs=item-description>This is the item description</div>
</div>
<div class="grid-item">
<img src="https://pbs.twimg.com/media/CZsY7k0WAAA_sk5.jpg" />
<div classs=item-description>This is the item description</div>
</div>
<div class="grid-item">
<img src="https://pbs.twimg.com/media/CZsY7k0WAAA_sk5.jpg" />
<div classs=item-description>This is the item description</div>
</div>
<div class="grid-item">
<img src="https://pbs.twimg.com/media/CZsY7k0WAAA_sk5.jpg" />
<div classs=item-description>This is the item description</div>
</div>
</div>
Basically, I need the images on the last row to be the same size as the others while the flex property of the images is maintained. How can I achieve that?