I know that my answer will look strange, but I think that the float on the left may be what you are looking for (yes, I hate swimming myself)
But if you get rid of all the flex material of your example and add margin directly to mat-card
<div class="mat-elevation-z0" *ngIf="postcards != null"> <mat-card *ngFor="let postcard of postcards let index = index" > <img mat-card-image src="{{postcard.img}}" alt="{{postcard.postcard_id}}" class="postcards" (click)="display_postcard(index)"> </mat-card> </div> mat-card { margin: 1rem; float: left; }
Your map will try to fit into the available space. But of course, this is not a perfect match for all occasions. But I think this is the best CSS based solution you can find.
source share