I'm trying to render a dynamic (css) grid with unknown number of items (javascript generated).
What I need is to have all items (obviously resized) in width 100% and height 100%.
Examples:
- 1 item: big square
- 2 items: 2 big squares (2 horizontal columns)
- 3 items: screen in 4 squares, 1, 2, 3 divs, 4 (latest one) empty
- 4 items: screen in 4 squares
- and so on...
- 1920 items (on 1920x1080 display): every item resized very very small (maybe just one pixel or less considering gap between) (with no text inside) in the same number of columns and rows (but this is just an extreme example, just for meaning!)
What I have done alone: https://jsfiddle.net/fredhors/s4k3z9t2/8/
CSS:
.grid-wrapper {
display: grid;
grid-template-columns: repeat(auto-fit, 10vmax);
grid-gap: 0.5rem;
height: 100vh;
}
.grid-item {
background: red;
}