I’m not actually sure my title is correct.
I have this JS code that generates images from a directory.
In this code I want to add several images from other directory but give them specific places in my css grid.
The JS overrides this because of being launched after the css script.
I tried adding !important and inline css but nothing changes.
js code :
<script async defer>
var imagePath = "./img/seperate-";
var numberOfImage = 208;
var parentDIV = document.getElementsByClassName("grid-container-parent")[0];
for (var i = 0; i < numberOfImage; i++) {
var tempDIV = document.createElement('div');
tempDIV.setAttribute('class', 'grid-container-parent', 'test');
var innerHTML = `<img src='` + (imagePath + i) + `.png'></img>`
tempDIV.innerHTML = innerHTML;
parentDIV.appendChild(tempDIV);
}
</script>
html:
<div class="grid-container">
<div class="grid-container-parent">
<img class=".other img" href="img2/other.img">
</div>
</div>
css:
.grid-container {
display: grid;
height: 400px;
width: auto;
grid-template-columns: repeat( auto-fit, minmax(90px, 1fr));
grid-template-rows: repeat( auto-fit, minmax(120px, 1fr));
margin: 0;
}
.grid-container-parent img {
display: grid;
gap: 0px 0px;
height: 115px;
width: 98.44px;
object-fit: cover;
float: left;
grid-column: auto;
}
.other {
display: grid;
gap: 0px 0px;
height: 115px;
width: 98.44px;
object-fit: cover;
grid-column: 22 !important;
grid-row: 4 !important;
}