I have 1500 divs (nothing should be displayed into them) and I would like based on the size of the viewport size to build a grid that best fill in the viewport. Divs should fill the rows up to the end of the viewport and the columns up to the height of the viewport. It is ok when the last line contains empty space at the end when the divs cannot be distributed to fully fill the last line.
The number of divs is fixed.
What would be the best approach to reach this in CSS? Would JS here be required to calculate how to best size the divs related to the viewport resolution?
Thanks!
Edit: I have obtain the wrap and the display, but I would like to further refine it in order for the divs to have a better width/height ratio (they should look as closer as possible to a quadrat...)
.flex-container {
display: flex;
width: 100%;
height: 100vh;
flex-flow: row wrap;
background-color: DodgerBlue;
}
.flex-container > div {
background-color: #f1f1f1;
width: 100px;
margin: 2px;
text-align: center;
}
<!DOCTYPE html>
<html>
<body>
<div class="flex-container">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<!--another 1495 divs here-->
</div>
</body>
</html>
<>button to make it a runnable snippet.