The following code generates a masonry layout:
<ngx-masonry class="masonry" [options]="myOptions">
<div ngxMasonryItem class="masonryItem" *ngFor="let post of posts;index as idx" (click)="showPostDetail(post)" >
<div class="crop">{{post.description}}</div>
<img [src]="imgConstructor(post.img)">
</div>
</ngx-masonry>
Now the css code:
.masonryItem {
padding: 7px;
margin-top: 5px;
background-color: darkgoldenrod;
border: 0.4px solid black;
width: 20%;
}
.masonryItem img {
object-fit: cover;
max-width: 100%;
min-width: 100%;
}
So five images are displayed in a row since the width of each item is 20%. But now I want to include a margin-property in my css code in the masonryItem class
.masonryItem {
margin: 1rem
}
But then there would be only 4 images in a row and some space on the right on the masonry-grid. So how to bring in the margin-property in my width-calculation such that five images are displayed in each row?
MY SOLUTION:
Add a border property with 1rem:
.masonryItem{
border: 1rem solid white;
}
It looks like margin 1rem if the background-color and border-color is the same. Then the amount of images per row is identically.