Looking to create a gallery for images and videos using flexbox properties to create a dynamic table of divs to hold media.
The challenge is generating the table automatically without specifying the number of rows and columns needed.
For example, if I have 2 images, the table will have 2 elements. If I have 6 photos/videos, the table will have 3 rows with 2 columns each, and so on.
What I want:
https://i.sstatic.net/dTVVu.png
What I have:
https://i.sstatic.net/4mjna.png
Does anyone know if it's possible to create such a flexible table in flexbox without predefining rows and columns?
.container {
width: 100%;
height: 100%;
background-color: rosybrown;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.item {
background: red;
margin: 1%;
flex: auto;
}
<div class="container">
<div class="item">Item</div>
<div class="item">Item</div>
<div class="item">Item</div>
<div class="item">Item</div>
<div class="item">Item</div>
<div class="item">Item</div>
</div>