Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="wrapper">
  <img src="https://y38.org/wp-content/themes/y2021/images/copic.jpg">
</div>
              
            
!

CSS

              
                .wrapper{
  img {
    cursor: pointer;
    &.noclick {
      pointer-events: none;
    }
  }
}
.lightbox{
  position: fixed;
  z-index: 999;
  display: grid;
  justify-content: center;
  top: 0;
  left: 0;
  transition: 0.4s;
    img {
      display: block;
      width: auto;
      margin: auto;
      object-fit: contain;
      max-width: 80vw;
    }
    &.show {
      width: 100%;
      height: 100%;
      background-color: rgba(64,67,87, 0.85);
      backdrop-filter: blur(3px) saturate(60%);
      img {
        animation: fadein 0.6s both;
      }
    }
}
@keyframes fadein {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}
//------------------------------
*{
  margin:0;
  padding:0;
}
body{
  padding:1em;
}
.wrapper{
  width:90%;
  height:90%;
  padding:1em;
  border:1px solid black;
  img{
    width:70vw;
    height:70vh;
    object-fit:contain;
    display:block;
    margin:auto;
  }
}
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded", function () {
  const bd = document.querySelector("body");
  const wp = document.querySelector(".wrapper");
  //const lb = document.querySelector(".lightbox");
  const pt = document.querySelector(".wrapper img");
  let lb;
  let lb_pt;

  function lightbox() {
    //wp.insertAdjacentHTML("beforeend", '<div class="lightbox"></div>');
    //const lb = document.querySelector(".lightbox");
    lb = document.createElement("div"); //divを作成
    lb.setAttribute("class", "lightbox"); //divにclassを付与
    wp.appendChild(lb); //wpの中にdivを作成

    // created要素に対するクリックイベントを登録
    lb.addEventListener("click", close);

    const cp = pt.cloneNode(false);
    lb.appendChild(cp);
    //pt.classList.add("noclick");
    lb.classList.add("show");
    bd.classList.add("fixed");
    lb_pt = document.querySelector(".lightbox img");
    pt.removeEventListener("click", lightbox);
    return {
      lb,
      lb_pt,
    };
  }
  function close() {
    lb_pt.remove();
    lb.remove();
    pt.classList.remove("noclick");
    bd.classList.remove("fixed");
    pt.addEventListener("click", lightbox);
  }

  pt.addEventListener("click", lightbox);
});

              
            
!
999px

Console