Skip to content

Instantly share code, notes, and snippets.

@giventofly
Created May 21, 2018 08:55
Show Gist options
  • Save giventofly/3489dcb65a255386d19872e59dd65273 to your computer and use it in GitHub Desktop.
Save giventofly/3489dcb65a255386d19872e59dd65273 to your computer and use it in GitHub Desktop.
simple CSS lightbox effect
<!-- //original: https://codepen.io/gschier/pen/HCoqh -->
<!-- thumbnail image wrapped in a link -->
<a href="#img1">
<img src="http://insomnia.rest/images/screens/main.png" class="thumbnail">
</a>
<a href="#img2">
<img src="http://via.placeholder.com/1350x1150" class="thumbnail">
</a>
<!-- lightbox container hidden with CSS -->
<a href="#" class="lightbox" id="img1">
<img src="http://insomnia.rest/images/screens/main.png">
</a>
<a href="#" class="lightbox" id="img2">
<img src="http://via.placeholder.com/1350x1150">
</a>
<!--css-->
<style>
.thumbnail {
max-width: 20%;
}
/** LIGHTBOX MARKUP **/
.lightbox {
/** Default lightbox to hidden */
display: none;
/** Position and style */
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
text-align: center;
top: 0;
left: 0;
background: rgba(0,0,0,0.8);
}
.lightbox img {
/** Pad the lightbox image */
max-width: 90%;
max-height: 90%;
margin: 5%;
}
.lightbox:target {
/** Remove default browser outline */
outline: none;
/** Unhide lightbox **/
display: block;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment