- I want a flexible layout with auto width columns for future additions.
- Avoiding extra wrappers is preferred.
- CSS grid is the preferred method over flexbox (although flexbox can achieve it with wrappers).
This layout is intended for a navigation bar
.container {
display: grid;
grid-template-columns: auto 1fr auto;
grid-gap: 5px;
align-items: flex-start;
margin-bottom: 10px;
}
.item--1,
.item--3 {
grid-column: 1fr;
width: 100px;
}
.item--2 {
color: #fff;
line-height: 100px;
text-align: center;
font-size: 30px;
}
.item {
height: 100px;
background: deepskyblue;
}
@media screen and (max-width: 768px) {
.container-1 {
grid-template-rows: auto auto;
}
.item--1 {
grid-column: 1 / 2;
}
.item--2 {
grid-row-start: 2;
grid-column: 1 / -1;
}
.item--3 {
grid-column: 3 / 4;
}
}
<div class="container">
<div class="item item--1"></div>
<div class="item item--2">Fill up remaining space</div>
<div class="item item--3"></div>
</div>