Weekend in Lisbon
Three days of tiles, tarts and trams.
A square thumbnail turns a quarter of a turn as its corners round off into a circle, while the photo inside counter-rotates and zooms so it stays level. The wrapper never moves, so hover is steady.
Also known as: rounded image hover, border radius morph, avatar circle hover.
<div class="hfx-image-circle-morph">
<div class="hfx-image-circle-morph-frame">
<div class="hfx-image-circle-morph-photo" role="img" aria-label="Sunset at sea"></div>
</div>
</div>.hfx-image-circle-morph {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
width: 8.5em;
height: 8.5em;
}
.hfx-image-circle-morph-frame {
height: 100%;
border-radius: 1em;
overflow: hidden;
transition: border-radius 0.6s cubic-bezier(0.65, 0, 0.35, 1), transform 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-image-circle-morph-photo {
height: 100%;
background:
radial-gradient(9% 30% at 50% 74%, rgb(255 255 255 / 0.55), transparent),
linear-gradient(transparent 62%, color-mix(in srgb, var(--c) 78%, #0f172a) 62%, color-mix(in srgb, var(--c) 62%, #0f172a) 74%, color-mix(in srgb, var(--c) 40%, #020617)),
radial-gradient(34% 16% at 6% 63%, color-mix(in srgb, var(--c) 36%, #0f172a) 99%, transparent),
radial-gradient(20% 9% at 92% 62%, color-mix(in srgb, var(--c) 48%, #1e293b) 99%, transparent),
radial-gradient(circle at 50% 50%, #fffbeb 0 0.9em, rgb(254 243 199 / 0.5) 1em, transparent 3.6em),
linear-gradient(color-mix(in srgb, var(--c) 56%, #fff), color-mix(in srgb, var(--c) 18%, #fed7aa) 62%);
transition: transform 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-image-circle-morph:hover .hfx-image-circle-morph-frame {
border-radius: 50%;
transform: rotate(45deg);
}
.hfx-image-circle-morph:hover .hfx-image-circle-morph-photo {
transform: rotate(-45deg) scale(1.25);
}
@media (prefers-reduced-motion: reduce) {
.hfx-image-circle-morph, .hfx-image-circle-morph *, .hfx-image-circle-morph::before, .hfx-image-circle-morph::after, .hfx-image-circle-morph *::before, .hfx-image-circle-morph *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}The same effect using Tailwind utility classes. No custom CSS or config needed.
<div class="group size-36">
<div class="h-full overflow-hidden rounded-2xl transition-all duration-500 group-hover:rotate-45 group-hover:rounded-[50%]">
<div class="h-full bg-gradient-to-b from-orange-200 via-sky-300 to-blue-700 transition-transform duration-500 group-hover:-rotate-45 group-hover:scale-125"></div>
</div>
</div>--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.