Weekend in Lisbon
Three days of tiles, tarts and trams.
An accent ring springs out around the photo on hover and keyboard focus, with a small gap, while the photo nudges in. It is outline-offset, so the ring takes no layout space and follows the radius.
Also known as: outline offset hover, image border on hover, focus ring image.
<a href="#" class="hfx-image-outline-ring" aria-label="Open photo"> <span class="hfx-image-outline-ring-photo"></span> </a>
.hfx-image-outline-ring {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
display: block;
width: 14em;
height: 8.75em;
border-radius: 0.75em;
overflow: hidden;
outline: 0.15em solid transparent;
outline-offset: 0;
transition: outline-offset 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), outline-color 0.25s ease;
}
.hfx-image-outline-ring-photo {
display: block;
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.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-outline-ring:is(:hover, :focus-visible) {
outline-color: var(--c);
outline-offset: 0.35em;
}
.hfx-image-outline-ring:is(:hover, :focus-visible) .hfx-image-outline-ring-photo {
transform: scale(1.06);
}
@media (prefers-reduced-motion: reduce) {
.hfx-image-outline-ring, .hfx-image-outline-ring *, .hfx-image-outline-ring::before, .hfx-image-outline-ring::after, .hfx-image-outline-ring *::before, .hfx-image-outline-ring *::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.
<a href="#" class="group block h-36 w-56 overflow-hidden rounded-xl outline outline-2 outline-offset-0 outline-transparent transition-all duration-300 hover:outline-offset-4 hover:outline-blue-500"> <span class="block h-full bg-gradient-to-b from-sky-300 via-blue-400 to-blue-800 transition-transform duration-500 group-hover:scale-105"></span> </a>
--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.