Weekend in Lisbon
Three days of tiles, tarts and trams.
Images sit in black and white until hovered, then bloom into color and grow a touch. A filter transition does all the work, so it applies to any img or background.
Also known as: black and white hover, color on hover, desaturate hover.
<div class="hfx-image-grayscale" role="img" aria-label="Sample image"></div>
.hfx-image-grayscale {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
width: 12em;
aspect-ratio: 4 / 3;
border-radius: 0.75em;
background: linear-gradient(135deg, color-mix(in srgb, var(--c) 45%, #fff), var(--c));
filter: grayscale(1);
transition: filter 0.4s ease, transform 0.4s ease;
}
.hfx-image-grayscale:hover {
filter: grayscale(0);
transform: scale(1.03);
}
@media (prefers-reduced-motion: reduce) {
.hfx-image-grayscale, .hfx-image-grayscale *, .hfx-image-grayscale::before, .hfx-image-grayscale::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.