JSFiddle - React, Tailwind, and code Playground
by Slava
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lightbox with Popover API (No JavaScript)</title>
<style>
</style>
</head>
<body>
<button popovertarget="lightbox">
<img src="https://picsum.photos/800/600" class="thumbnail">
</button>
<div id="lightbox" class="lightbox" popover>
<img src="https://picsum.photos/800/600" class="fullscreen-image">
<button class="close-button" popovertarget="lightbox" popovertargetaction="hide">×</button>
</div>
</body>
</html>
CSS
.thumbnail {
width: 100px;
height: 100px;
object-fit: cover;
cursor: pointer;
}
.lightbox {
background: rgba(0, 0, 0, 0.8);
transition: all 0.3s ease;
opacity: 0;
transform: scale(0.8);
}
.lightbox:popover-open {
opacity: 1;
transform: scale(1);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
cursor: zoom-out;
}
.fullscreen-image {
max-width: 100%;
max-height: 100vh;
object-fit: contain;
}
.close-button {
position: absolute;
top: 20px;
right: 20px;
color: white;
font-size: 24px;
cursor: pointer;
background: none;
border: none;
}