Вот идея с flexbox и без дополнительной оболочки:
.container {
display: flex;
grid-gap: 5px;
margin-bottom: 10px;
}
/* this is your gap */
.item:not(:last-child) {
margin-right: 5px;
}
/**/
.fill {
color: #fff;
line-height: 100px;
text-align: center;
font-size: 30px;
flex-grow: 1; /* fill the remaining space */
}
.item {
height: 100px;
width: 100px;
background: deepskyblue;
margin-bottom: 5px;
}
@media screen and (max-width: 768px) {
.container {
flex-wrap: wrap; /* allow the wrap */
}
.fill {
order: 2; /* make the element the last on*/
flex-basis: 100%; /* 100% width */
margin-right: 0!important;
}
.fill + * {
margin-left: auto; /* keep the element on the left */
}
}
<div class="container">
<div class="item"></div>
<div class="item fill">Fill up remaining space</div>
<div class="item"></div>
<div class="item"></div>
</div>