Hi so I want to show a random number of articles in columns without wrapping but filling the extra space at the end.
The articles has to be shown every 4 of them taking the entire available width and then, by scrolling horizontally you can move to the next 4 and so on. If there are less than 4 or any multiple of it, I want the remainder to be filled empty.
So My try was this:
section {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(25%, 1fr));
grid-auto-flow: column;
overflow:scroll;
}
article {
background-color: lightblue;
margin: 10px;
white-space: nowrap;
height: 40px;
}
<section>
<article>Article 1</article>
<article>Article 2</article>
<article>Article 3</article>
<article>Article 4</article>
<article>Article 5</article>
<article>Article 6</article>
</section>
As you can see, the first 4 columns are properly rendered, the overflown ones, are not taking anymore 25% of the space (to fit 1/4) and there are no extra spaces filled after the last 2. (in this case, there should be 2 more white)
Is it there anything I can do to achieve this with CSS Grid? Remember the total space available is dynamic as well as the number of articles. Ideally I would like Grid to always render multiples of 4 columns covering the gap.