Pure CSS Galley Carousel with Keypress?

Hi I have a pure css carousel lightbox which is working fine.

However, I would like to do three things:
-when i press ESC it simulates clicking the close button;
-when pressing left and right it simulates clicking the left/right button; and,
-when i click off the image, the lightbox closes.
Ideally it would be great if this can be done in pure css.

Here is a fiddle.

(If not, willing to accept jquery :P)

Here is what I have:

<span class="feature_category active" id="A">
  <div class="feature_box_wrapper"><a href="#groys1">Link</a></div>
  <div class="feature_box_wrapper"><a href="#groys2">Link</a></div>
  <div class="feature_box_wrapper"><a href="#groys3">Link</a></div>
   <div class="feature_box_wrapper"><a href="#groys4">Link</a></div>
   <div class="feature_box_wrapper"><a href="#groys5">Link</a></div>
</span>

<div class="lightbox">
  <!-- Groys -->
  <div class="lightbox__slide" id="groys1">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys5" class="btn btn--left"></a>
    <a href="#groys2" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>
  <div class="lightbox__slide" id="groys2">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys1" class="btn btn--left"></a>
    <a href="#groys3" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>
  <div class="lightbox__slide" id="groys3">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys2" class="btn btn--left"></a>
    <a href="#groys4" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>
  <div class="lightbox__slide" id="groys4">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys3" class="btn btn--left"></a>
    <a href="#groys5" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>
  <div class="lightbox__slide" id="groys5">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys4" class="btn btn--left"></a>
    <a href="#groys1" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>


  <div class="lightbox__bg"></div><!-- Close -->
</div><!-- Close Lightbox -->

CSS

.lightbox__slide img {
  position: absolute;
  z-index: 30;
  max-width: 90%;
  max-height: 80%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-name: hide;
  animation-duration: 0.5s;
  animation-iteration-count: 1;
  animation-direction: linear;
  animation-fill-mode: forwards;
}

.lightbox__slide:target .btn {
  display: block;
}

.lightbox__slide:target img {
  opacity: 0;
  animation-name: show;
  animation-duration: 0.5s;
  animation-iteration-count: 1;
  animation-direction: linear;
  animation-fill-mode: forwards;
}

.lightbox__slide:target~.lightbox__bg {
  position: relative;
  background: white;
  opacity: 0.6;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

@-webkit-keyframes show {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@-webkit-keyframes hide {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

.btn {
  position: absolute;
  z-index: 20;
  display: none;
  transition: all 0.2s;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  text-align: center;
  line-height: 40px;
  text-decoration: none;
  color: black;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.8);
}

.btn--close {
  top: 40px;
  right: 20px;
}

.btn--close:after {
  content: '\2715';
}

.btn--left {
  top: 50%;
  left: 40px;
}

.btn--left:after {
  content: '⯇';
}

.btn--right {
  top: 50%;
  right: 20px;
}

.btn--right:after {
  content: '⯈';
}

Unfortunately, for handling keyboard events, you’ll have to go into JavaScript territory. There are ways to hook into some of the default input elements’ keyboard behavior, but I consider those more hacks than not. This article can help you get started: https://www.kirupa.com/html5/keyboard_events_in_javascript.htm

:slight_smile: