I have a collection of 100 images in the same size that I would like to arrange within a CSS grid.
The folder contains:
- seperate-0.png
- seperate-1.png
- seperate-2.png
- seperate-3.png
- and so on...
The CSS code below shows the grid structure:
html,
body,
.grid-container {
height: 100%;
margin: 0;
}
.grid-container {
display: grid;
grid-template-columns: repeat(7, 1fr);
grid-template-rows: repeat(7, 1fr);
gap: 0px 0px;
grid-template-areas: ". . . . . . ."
". . . . . . ."
". . . . . . ."
". . . . . . ."
". . . . . . ."
". . . . . . ."
". . . . . . .";
}
/* For presentation only, no need to copy the code below */
.grid-container * {
border: 1px solid red;
position: relative;
}
.grid-container *:after {
content: attr(class);
position: absolute;
top: 0;
left: 0;
}
Below is the HTML structure:
<div class="grid-container">
<div class="grid-container">img 1 here</div>
</div>
My question is, how can I dynamically populate this grid with the images from the folder? Would it be possible to generate divs based on the contents of the directory?