Tell us what’s happening:
Lightbox viewer can’t fullfill test 14: When you click one of your .gallery-item elements, the .lightbox element’s display property should be set to flex to make .lightbox and the two elements within it visible.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Lightbox Viewer</title>
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<div class="gallery">
<img src = "https://cdn.freecodecamp.org/curriculum/labs/stonehenge-thumbnail.jpg" class="gallery-item">
<img src = "https://cdn.freecodecamp.org/curriculum/labs/storm-thumbnail.jpg" class="gallery-item">
<img src = "https://cdn.freecodecamp.org/curriculum/labs/trees-thumbnail.jpg" class="gallery-item">
</div>
<div class="lightbox">
<span id="close">×</span>
<img id="lightbox-image" src="https://cdn.freecodecamp.org/curriculum/labs/stonehenge.jpg">
</div>
<script src="./script.js"></script>
</body>
</html>
/* file: script.js */
const images = document.querySelector(".gallery");
const lightbox = document.querySelector(".lightbox")
const lightboxImage = document.getElementById("lightbox-image");
const close = document.getElementById("close")
images.addEventListener("click", clickThumbnail);
close.addEventListener("click", closeImage);
lightbox.addEventListener("click", closeImage);
function clickThumbnail(event){
lightbox.style.display = "flex";
const thumbnailLink = event.target.src;
const lightboxLink = thumbnailLink.replace("-thumbnail", "");
lightboxImage.src = lightboxLink;
}
function closeImage(){
lightbox.style.display = "none";
}
/* file: styles.css */
.gallery {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
padding-top: 50px;
margin: 0 auto;
}
.gallery-item {
width: 250px;
height: 250px;
}
body{
background-color:black;
}
.lightbox {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
display: none;
justify-content: center;
align-items: center;
}
#lightbox-image{
height:80vh;
width:80vw;
}
#close{
position:fixed;
top:5%;
right:5%;
z-index:1000;
color:white;
font-size:50px;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Challenge Information:
Build a Lightbox Viewer - Build a Lightbox Viewer