I've been working on a website that showcases an ever-evolving gallery of fantasy art. Currently, I've encountered a roadblock in figuring out how to proceed with something that's not functioning as expected. I tried using Masonry and Wookmark without success, so now I'm exploring other options. My goal is to dynamically create either divs or spans within the grid
with the class identifier images
and set their backgrounds to specific image sources that "cover" the area while being centered. Essentially, I want to create a grid of square windows showcasing these images, which can be clicked to open a lightbox (that I've already created successfully). However, at the moment, although the images are displaying, the containers seem compressed with no padding on the sides.
Truth be told, I'm uncertain about how to handle relative/absolute positioning and inline/block display properties. I suspect this is where my mistake lies, but I lack a clear understanding of what these concepts involve.
Snippet of the HTML:
<div id="grid" class="grid"></div>
<br>
CSS:
.grid {
z-index:2;
display: inline-block;
}
.images {
display: inline-block;
position: relative;
width: 25%;
height: 25%;
z-index: 2;
padding-right: 0.25em;
padding-left: 0.25em;
padding-top: 0.5em;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
}
Javascript:
var mix = shuffle(Object.keys(backInfo));
function unlockImages () {
setTimeout(function () {
if (mix !== undefined) {
var input = mix.shift();
var entry = backInfo[input];
var elem = document.createElement("div");
elem.setAttribute("class", "images");
elem.setAttribute("id", input);
elem.setAttribute("title", entry.caption);
elem.setAttribute("onclick", "javascript:changeImage(" + input + ");");
document.getElementById("grid").appendChild(elem);
document.getElementById(input).style.backgroundImage = "url(" + entry.image + ")";
$("#" + input).fadeTo(0,0);
$("#" + input).fadeTo(20000,1);
unlockImages();
}
}, 0)
}
To see a live preview of the current progress, visit: