A fashion product card built with Tailwind CSS that cross-fades from the product shot to a second photo, such as the item worn by a model or the back print, when the shopper hovers the image. The grid of three T-shirt cards includes a sale badge, struck-through old price, color dots and a quick add bar for clothing stores and lookbooks.
How it works
The root is section.fhc-root, holding a responsive grid of article.fhc-card elements. Each card stacks two images in a fixed aspect-[4/5] frame: .fhc-img-front and .fhc-img-back, both absolutely positioned with object-cover. The card is a Tailwind group, so group-hover:opacity-0 fades the front photo out while group-hover:opacity-100 and a slight scale change bring the second photo in. The same swap is driven by the data-fhc-alt attribute through group-data-[fhc-alt=true]: utilities, which is how touch and keyboard users reach it.
The round [data-fhc-swap] button toggles data-fhc-alt and its own aria-pressed state. The product name link uses an after:absolute after:inset-0 overlay so the whole card is clickable while the buttons stay on top. In style.css the .fhc-quick bar is hidden on devices with a mouse and revealed on hover or focus, but always visible on touch screens.
On load, the card marked data-fhc-demo shows its second photo so the effect is visible right away; the script resets it on the first mouse pointerenter. Clicking [data-fhc-add] changes the label to "Added to bag" for two seconds and updates a status message.
Customization
- Replace the two
srcURLs in each card with your product and alternate photos. The photos come from Unsplash; swap them for your own images in the same 4:5 ratio, or changeaspect-[4/5]toaspect-square. duration-500on.fhc-img-frontand.fhc-img-back: make the cross-fade faster or slower; removegroup-hover:scale-105for a pure fade without zoom.bg-[#f4f1ec]on the root andbg-[#b4532a]on the sale badge and Quick add hover: change the page tone and accent color.font-serifon the heading and product names: switch tofont-sansfor a more technical store look.- Remove
data-fhc-demofrom the second card if you do not want any card to start on its second photo. sm:grid-cols-2 lg:grid-cols-3on the list: uselg:grid-cols-4for a denser category page.- The
[data-fhc-add]click handler inscript.js: call your cart API there instead of the label change.
Use cases
- Fashion stores: cards cross-fade to a second photo on hover to show another angle
- Clothing catalogs: sale badges mark discounted items at a glance
- Mobile shops: a touch-friendly swap button replaces hover on phones
- Ecommerce grids: a quick add bar lets shoppers add items without leaving the listing
Accessibility
Each card is an article labelled by its product name, and both images have descriptive alt text. The swap button exposes aria-pressed and an aria-label such as "Show back view", so keyboard and screen reader users get the second photo without hovering. Prices use sr-only "Was" and "Now" prefixes, color dots have hidden text names, and a role="status" region announces added items. All controls have visible focus rings, and transitions and zoom are disabled under prefers-reduced-motion.
Usage notes
Images use loading="lazy"; keep width and height to avoid layout shift. Several grids can share a page because the script scopes everything to each .fhc-root.