Weekend in Lisbon
Three days of tiles, tarts and trams.
The photo pushes in and turns a few degrees inside a fixed frame, a livelier cousin of the plain zoom. Scaled to 1.25 so the rotated corners never show past the rounded edges.
Also known as: rotate image on hover, zoom rotate hover css, tilt zoom image.
<div class="hfx-image-zoom-rotate"> <div class="hfx-image-zoom-rotate-photo" role="img" aria-label="Mountain range"></div> </div>
.hfx-image-zoom-rotate {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
width: 15em;
height: 9.5em;
border-radius: 0.75em;
overflow: hidden;
}
.hfx-image-zoom-rotate-photo {
height: 100%;
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%);
transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-zoom-rotate:hover .hfx-image-zoom-rotate-photo {
transform: scale(1.25) rotate(-6deg);
}
@media (prefers-reduced-motion: reduce) {
.hfx-image-zoom-rotate, .hfx-image-zoom-rotate *, .hfx-image-zoom-rotate::before, .hfx-image-zoom-rotate::after, .hfx-image-zoom-rotate *::before, .hfx-image-zoom-rotate *::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 h-36 w-60 overflow-hidden rounded-xl"> <div class="h-full bg-gradient-to-b from-sky-300 via-blue-400 to-blue-800 transition-transform duration-500 ease-out group-hover:-rotate-6 group-hover:scale-125"></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.