Gallery · 28 of 33

Mirror Split

Splits and slides apart

HTML · CSS · No dependencies · MIT

HTML

<div class="mirror-split">
  <div class="mirror-half m-left">
    <img src="https://picsum.photos/id/193/800/600" alt="Mirror">
  </div>
  <div class="mirror-half m-right">
    <img src="https://picsum.photos/id/193/800/600" alt="Mirror">
  </div>
</div>

CSS

.mirror-split {
  position: relative;
  width: 400px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 12px;
  background: #0a0a0f;
}

.mirror-half {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Each half holds a full-width copy of the image, offset so the
   two halves line up as one picture */
.mirror-half img {
  position: absolute;
  width: 200%;
  height: 100%;
  object-fit: cover;
}

.m-left { left: 0; }
.m-left img { left: 0; }
.m-right { right: 0; }
.m-right img { left: -100%; }

.mirror-split:hover .m-left { transform: translateX(-10px); }
.mirror-split:hover .m-right { transform: translateX(10px); }