I'm building an app that needs a grid system, here's how far I've come:
I have a problem: Each of the blocks should fill up the entire space of the grid
As you can see, the black block is not occupying the rest of the space. I want the boxes to occupy the rest white space(but all their widths should be the same).
I've read Expand a div to fill the remaining width and Make last element take remaining width with wrapping (and with IE9 support), but they don't answer the case of the dynamically wrapping grid that is here the important part since they are made for float
and display: block
.
Now let's look at the code:
HTML:
<div className='container'>
<div className="item"></div>
<div className="item"></div>
<div className="item"></div>
<div className="item"></div>
<div className="item"></div>
<div className="item"></div>
<div className="item"></div>
</div>
CSS:
container {
overflow: hidden;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.item {
height: 300px;
min-width: 300px;
background-color: red;
border: 2px solid yellow;
}
.container
is the grid parent and .item
s are the children. Keep in mind that the solution should work with any number of children(.item
). Thank you in advance!