I have found the answer to your question I have reproduced it here:
https://jsfiddle.net/nmcobalt/dg3mutwv/13/
In order to do the css less complicate and solve this complex issue, it is recommended to use SCSS* instead of plain css.
In SCSS file you have to use the css selector nth:last-child with iteration calculating childs based on modulo function and the constant factor of the 3 columns.
@mixin setLastChildFluid{
@for $i from 1 through 10 {
$span: 3;
@if $i % 3 == 0{
$span: 1;
} @else if $i % 3 == 1{
$span: 3;
} @else if $i % 3 == 2{
$span: 2;
}
@if $span == 2 {
span:nth-child(#{$i - 1}){
&:nth-last-child(2){
grid-column-end:span 1;
position:relative;
bottom:0;
width:calc(150% + 5px);
left:0;
}
}
span:nth-child(#{$i}){
&:nth-last-child(1){
grid-column-start:2;
position:relative;
bottom:0;
width:calc(150% + 5px);
left:calc(50% + 5px);
}
}
} @else {
span:nth-child(#{$i}){
&:last-child{
grid-column-end:span #{$span};
}
}
}
}
}
div {
position:relative;
margin:20px auto;
width: 400px;
background: #d8d8d8;
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(3, 1fr);
@include setLastChildFluid;
}
span {
height: 50px;
background: blue;
color:yellow;
}
and the following html markup; I have done two different examples (wrapped by div) to reproduce your query:
<div>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
</div>
<div>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
</div>
Change the number of divs in order to see the fluid result.
*SASS is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets (CSS). Learn more here: https://sass-lang.com/guide