// Accessing the modal
var modal = document.getElementById("myModal");
// Finding and placing the image inside the modal - utilizing its "alt" text as a caption
var img = document.querySelectorAll(".column img");
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption-gallery-fu-sc");
img.forEach((imgA)=>{
imgA.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
});
// Closing modal when clicking on close button
var span = document.getElementsByClassName("close-gallery-fu-sc")[0];
span.onclick = function() {
modal.style.display = "none";
}
.row {
display: -ms-flexbox; /* For IE 10 */
display: flex;
-ms-flex-wrap: wrap; /* For IE 10 */
flex-wrap: wrap;
padding: 0 4px;
}
/* Creating two columns that sit next to each other */
.column {
-ms-flex: 50%; /* For IE 10 */
flex: 50%;
padding: 60px 4px;
}
.column img {
margin-top: 8px;
vertical-align: middle;
}
/* Styling the Image Used to Trigger the Modal */
#image-gall-1,#image-gall-2,#image-gall-3,#image-gall-4,#image-gall-5,#image-gall-6,#image-gall-7,#image-gall-8,#image-gall-9,#image-gall-10,#image-gall-11,#image-gall-12,#image-gall-13 {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
#image-gall-1:hover, #image-gall-2:hover, #image-gall-3:hover, #image-gall-4:hover, #image-gall-5:hover,#image-gall-6:hover, #image-gall-7:hover, #image-gall-8:hover, #image-gall-9:hover, #image-gall-10:hover, #image-gall-11:hover, #image-gall-12:hover, #image-gall-13:hover {opacity: 0.7;}
/* The Modal (background) */
.modal-gallery-fu-sc {
display: none; /* Initially hidden */
position: fixed; /* Fixed position */
z-index: 1; /* On top of other elements */
padding-top: 100px; /* Positioning */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.9); /* Black with opacity */
}
... (CSS omitted for brevity)
<div class="container">
<!-- The Modal -->
<div id="myModal" class="modal-gallery-fu-sc">
<!-- The Close Button -->
<span class="close-gallery-fu-sc">×</span>
<!-- Modal Content (The Image) -->
<img class="modal-content-gallery-fu-sc" id="img01">
<!-- Modal Caption (Image Text) -->
<div id="caption-gallery-fu-sc"></div>
</div>
<!-- Photo Grid -->
<div class="row">
<div class="column">
<img id="image-gall-1" src="https://www.w3schools.com/w3images/wedding.jpg" alt="wedding" style="width:100%">
... (Additional image entries omitted for brevity)
</div>
<div class="column">
... (Additional image entries omitted for brevity)
</div>
</div>
</div>