I want the items in the last row of a CSS Grid to expand if there is not enough to fill the row naturally.
I can easily achieve this using Flexbox.
.container {
display:flex;
flex-wrap:wrap;
margin:10px -5px;
}
.item {
background:#eee;
margin:0.5%;
padding:40px;
flex-grow:1;
flex-basis:25%;
}
<h2>Flex auto fiting last row elements</h2>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
</div>
The reason I want to do this with CSS Grid is it has grid-gap, which flexbox doesn't, which means using hacky code. You can see in my example the use of a negative margin on the container to offset the outer left and right margins of the items.
I have setup a codepen for the CSS Grid https://codepen.io/chrishoward/pen/ELdJxo and as you can see, the seventh item steadfastly refuses to expand to the width of the row.
I've spent hours on this today including CSS Tricks and Rachel Andrew's excellent examples, so not even sure if this is possible.
Thank you