I'm trying to find the best way to style my columns. If there are 4 posts then it works as hoped. But if a row has less than 4, there is additional space between each post. I know this is possible with floats but I'm hoping there is a more modern solution to this, ideally using flexbox. This is how it is currently set up. The second row is spaced differently than the first row.
This is the desired layout with all columns in line with each other
PHP
<div class="news-results">
<div class="container">
<!-- Each News Preview Card -->
<a href="<?php echo $link; ?>" class="news-card">
<div class="image-background">
<img src="<?php echo $preview_image['url']; ?>" alt="<?php echo $preview_image['alt']; ?>">
</div>
<div class="news-contents">
<h3><?php echo $title; ?></h3>
<p><?php echo $excerpt; ?></p>
<p><?php echo $date; ?></p>
</div>
</a>
</div>
</div>
SCSS
.news-results {
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
.news-card {
width: calc(25% - 20px);
.image-background,
.color-background {
height: 215px;
width: auto;
margin-bottom: 15px;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
}
.news-contents {
h3, p {
color: $black;
}
}
}
}
}
EDIT
Also, I need the posts to fill .container div so margin-right on all of them would not work. See img:
Thanks for your help!! :D
