JSFiddle - React, Tailwind, and code Playground

by Aaron von Schassen

HTML

<p>Runterscrollen<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br></p><p>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content</p>


<div class="lightbox">
  <div>
    <img alt="Es ist ein Fehler aufgetreten" src="">
    <div class="close"><span></span><span></span></div>
  </div>
</div>
<img onclick="lightbox()" class="small-picture" alt="Es ist ein Fehler aufgetreten" src="https://assets.pixolum.com/blog/wp-content/uploads/2016/10/focus-stacking-scharfe-bilder-1.jpg">



<p>Runterscrollen<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br></p><p>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content</p>

CSS

* {
  margin: 0;
  padding: 0;
}

body {
  background: white;
  overflow: auto;
  text-align: center;
}

.lightbox {
  display: none;
  position: fixed;
  z-index: 10000;
  height: 100%;
  width: 100%;
  justify-content: center;
  align-items: center;
  top: 0;
  background: rgba(0,0,0,0.4);
}

.lightbox > div {
  position: relative;
}

.lightbox img {
  border-radius: 5px;
  width: 90%;
  max-height: 90%;
  max-width: 600px;
}

.small-picture {
  width: 100%;
  max-width: 300px;
  max-height: 90vH;
}

.close {
  color: white;
  position: absolute;
  top: 0;
  right: 0;
}

.close > span:first-child {
  display: block;
  width: 10px;
  height: 15px;
  background: white;
  transform: rotate(45deg);
}

@media only screen and (max-height: 400px) {
  .small-picture {
    width: 100%;
    max-width: 300px;
    max-height: 90vH;
    width: auto;
  }
}

@media only screen and (max-height: 500px) {
  .lightbox img {
    max-width: 90%;
    max-height: 90%;
    width: auto;
  }
}

JavaScript

function lightbox() {
	var source = event.target.getAttribute("src");
  
  document.querySelector(".lightbox img").setAttribute("src", source);
  document.querySelector(".lightbox").style.display = "flex";
}