Weekend in Lisbon
Three days of tiles, tarts and trams.
The photo is cut down the middle and the two halves slide apart on hover to reveal a caption behind them. Each half shows its side of one background, sized to 200 percent.
Also known as: image split in half hover, doors open image reveal, split reveal hover.
<figure class="hfx-image-split-reveal">
<figcaption>
<strong>Tre Cime</strong>
<span>Dolomites, Italy</span>
</figcaption>
<div class="hfx-image-split-reveal-half" aria-hidden="true"></div>
<div class="hfx-image-split-reveal-half" aria-hidden="true"></div>
</figure>.hfx-image-split-reveal {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 15em;
height: 9.5em;
margin: 0;
border-radius: 0.75em;
overflow: hidden;
background: color-mix(in srgb, var(--c) 30%, #0f172a);
color: #fff;
font-family: system-ui, sans-serif;
text-align: center;
}
.hfx-image-split-reveal figcaption {
display: grid;
padding: 0;
color: inherit;
font: inherit;
gap: 0.2em;
opacity: 0;
transform: scale(0.85);
transition: opacity 0.3s ease, transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hfx-image-split-reveal strong {
font-size: 1.2em;
}
.hfx-image-split-reveal span {
font-size: 0.8em;
opacity: 0.75;
}
.hfx-image-split-reveal-half {
position: absolute;
inset: 0 50% 0 0;
background:
radial-gradient(74% 44% at 20% 110%, color-mix(in srgb, var(--c) 42%, #0f172a) 99%, transparent),
radial-gradient(62% 36% at 90% 107%, color-mix(in srgb, var(--c) 56%, #0f172a) 99%, transparent),
conic-gradient(from 130deg at 72% 40%, transparent 0, color-mix(in srgb, var(--c) 80%, #1e293b) 0.4deg 99.6deg, transparent 100deg),
conic-gradient(from 118deg at 94% 55%, transparent 0, color-mix(in srgb, var(--c) 80%, #1e293b) 0.4deg 123.6deg, transparent 124deg),
conic-gradient(from 124deg at 30% 36%, transparent 0, color-mix(in srgb, var(--c) 48%, #fff) 0.4deg 111.6deg, transparent 112deg),
conic-gradient(from 126deg at 52% 50%, transparent 0, color-mix(in srgb, var(--c) 48%, #fff) 0.4deg 107.6deg, transparent 108deg),
radial-gradient(circle at 55% 27%, #fff 0 0.85em, rgb(255 255 255 / 0.45) 0.95em, transparent 3.2em),
linear-gradient(color-mix(in srgb, var(--c) 64%, #fff), color-mix(in srgb, var(--c) 12%, #fff7ed) 72%);
background-size: 200% 100%;
transition: transform 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-image-split-reveal-half + .hfx-image-split-reveal-half {
inset: 0 0 0 50%;
background-position: 100% 0;
}
.hfx-image-split-reveal:hover .hfx-image-split-reveal-half {
transform: translateX(-76%);
}
.hfx-image-split-reveal:hover .hfx-image-split-reveal-half + .hfx-image-split-reveal-half {
transform: translateX(76%);
}
.hfx-image-split-reveal:hover figcaption {
opacity: 1;
transform: none;
transition-delay: 0.18s;
}
@media (prefers-reduced-motion: reduce) {
.hfx-image-split-reveal, .hfx-image-split-reveal *, .hfx-image-split-reveal::before, .hfx-image-split-reveal::after, .hfx-image-split-reveal *::before, .hfx-image-split-reveal *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--hfx-color on the element or a parent.
Currently previewing #3b82f6.--hfx-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.