Hi you must use javascript for handle it. I have a very very simple code for that. share that with you:
and Sure you must organize this for yourself.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Zoom Img</title>
<style>
* {
border: 0;
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
width: 90%;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
}
.pics {
display: flex;
flex-wrap: wrap;
width: 100%;
margin: 20px auto;
border-radius: 5px;
}
.pics img {
width: 33.3333%;
border-radius: 2px;
cursor: pointer;
}
.cover {
position: absolute;
/*display: flex;*/
top: 0;
left: 0;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.726);
margin: 0 auto;
display: none
}
.cover a {
text-decoration: none;
color: rgb(233, 44, 44);
font-size: 25px;
/* font-weight: 800; */
margin: 20px 20px 0 0;
background: rgb(49, 47, 43);
width: 30px;
height: 30px;
text-align: center;
border-radius: 50%;
padding-top: 2px;
position: absolute;
top: 15px;
right: 15px;
}
.cover #newImage {
position: absolute;
width: 80%;
z-index: 999;
border-radius: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="pics">
<img src="./images/1.jpg" alt="" onclick="zoomIn(this)">
<img src="./images/2.jpg" alt="" onclick="zoomIn(this)">
<img src="./images/3.jpg" alt="" onclick="zoomIn(this)">
<img src="./images/4.jpg" alt="" onclick="zoomIn(this)">
<img src="./images/5.jpg" alt="" onclick="zoomIn(this)">
<img src="./images/6.jpg" alt="" onclick="zoomIn(this)">
<img src="./images/7.jpg" alt="" onclick="zoomIn(this)">
<img src="./images/8.jpg" alt="" onclick="zoomIn(this)">
<img src="./images/9.jpg" alt="" onclick="zoomIn(this)">
</div>
</div>
<div class="cover">
<a href="#" onclick="closeCover(event)">X</a>
</div>
<script >
let cover = document.getElementsByClassName("cover")[0];
function zoomIn(img) {
let newImg = document.createElement("img");
newImg.src = img.src;
newImg.id = "newImage";
cover.appendChild(newImg);
cover.style.display = "flex";
}
function closeCover(e) {
e.preventDefault();
cover.removeChild(document.getElementById("newImage"));
cover.style.display = "none";
}
</script>
</body>
</html>
1
solved show clicked images in new template [closed]