Другим неожиданным способом может быть установка большого количества перекрывающих столбцов в последнем элементе и использование только grid-auto-columns: auto
, оставляя в стороне grid-template-columns.
.box {
display: grid;
grid-auto-flow: column;
/* grid-auto-columns: auto; useless here */
margin: 5px;
}
span {
border: 1px solid;
padding: 5px;
margin: 1px
}
span:last-child {
grid-column: span 100;
background: tomato
}
<div class="box">
<span>aa</span>
<span>b</span>
<span>ccc</span>
<span>d</span>
<span>eeee</span>
</div>
<div class="box">
<span>aa</span>
<span>b</span>
<span>eeee</span>
</div>
<div class="box">
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>break me with so many</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>aa</span>
<span>b</span>
<span>eeee</span>
</div>
хотя и не уверен, что отражает вашу реальность.
Другая альтернатива, очень похожая:
span {
border: solid;
padding: 1em;
margin: 1px;
min-width: min-content;
}
.box {
display: grid;
grid-auto-flow: column;
}
span:last-child,b {
color: tomato;
grid-column: span 70;
width: auto;
}
<div class="box">
<span>aa</span> <span>bbbbb bbbbbbbb bbbbbbbb bbbbbbbb bbbbbbb bbbbbbbb bbbbbbbbb</span>
<span><b>To be tested in fullpage mode too.</b></span>
<span>desd</span>
<span>/</span>
</div>
и давайте сделаем еще один без охвата, но с использованием псевдо последнего ребенка
span {
border: solid;
padding: 1em;
margin: 1px;
}
.box {
display: grid;
grid-auto-flow: column;
}
span:last-child {
color: tomato;
/* trick start */
overflow: hidden;
}
span:last-child:after {
content: "";
display: block;
width: 100vw;
}
/* trick end */
<div class="box">
<span>aa</span> <span>bbbbb bbbbbbbb bbbbbbbb bbbbbbbb bbbbbbb bbbbbbbb bbbbbbbbb</span>
<span>cccc ccc ccccccc ccc cccccc cccccccccc</span>
<span>desd</span>
<span>last child</span>
</div>