Theme
Design your own
On this page (5)
Component Skill — components/collection-item/component-skill.md

Native basis

An <article>: a picture, the collection name as a link covering the card, the number of products and a decorative "Shop now" cue.

Web Platform APIs

<article>:has()object-fitaspect-ratio

Classes

.mk-collection-item.mk-collection-item-title.mk-collection-item-media.mk-collection-item-body.mk-collection-item-count.mk-collection-item-more.mk-collection-item-badge.mk-collection-item-stack

Data attributes

data-variant: overlay, stack, banner; data-tone="sale" on the badge; --mk-collection-tint for the stack's panel.

§Banner

data-variant='banner': a wide 21:9 picture with the copy on the start side and a pill cue.

§Grid

Default: a 4:5 picture, the collection name - a link covering the card - the count and a "Shop now" cue. On hover or keyboard focus the card lifts, its picture casts a shadow and the cue underlines. .mk-collection-item-badge labels a card over its picture (data-tone="sale" for a reduction).

§Overlay

data-variant='overlay': the name over the picture with a scrim; the badge turns to glass, the picture zooms a little and the cue rises on hover or focus (always shown on touch screens).

§Stack

data-variant='stack': three pictures of the collection as prints on a tinted panel (.mk-collection-item-stack, the tint from --mk-collection-tint); they fan out on hover or focus.

§CSS view file

/* -- Collection Item (website · Shop) -------------------------------------
   Links to one product collection with imagery and context - a picture with the name and count, text over the picture, or a wide banner. */
@layer components {
  /* every box in the block measures border-box - the same on any page */
  :where(.mk-collection-item, .mk-collection-item *, .mk-collection-item ::before, .mk-collection-item ::after) {
    box-sizing: border-box;
  }
  .mk-collection-item {
    display: grid;
    gap: 0.875rem;
  }
  .mk-collection-item {
    position: relative;
  }
  .mk-collection-item-title a::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
  }
  .mk-collection-item-title a:focus-visible {
    outline: none;
  }
  .mk-collection-item:has(.mk-collection-item-title a:focus-visible) {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
  }
  /* zero specificity: any block rule may still position its controls */
  :where(.mk-collection-item :is(button, input, select, label, .btn):not(.mk-collection-item-title a)) {
    position: relative;
    z-index: 1;
  }
  .mk-collection-item:has(.mk-collection-item-title a:focus-visible) {
    border-radius: var(--radius-xl);
  }
  .mk-collection-item-media {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 5;
    object-fit: cover;
    border-radius: var(--radius-xl);
    background: var(--muted);
    transition:
      scale 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
      filter 300ms ease;
  }
  /* the card lifts, its picture casts a shadow and warms up */
  .mk-collection-item {
    transition: translate 300ms cubic-bezier(0.2, 0.7, 0.2, 1);
  }
  .mk-collection-item:not([data-variant]):is(:hover, :has(:focus-visible)) {
    translate: 0 -0.25rem;
    & .mk-collection-item-media {
      box-shadow: var(--shadow-lg);
      filter: saturate(1.15);
    }
    & .mk-collection-item-more {
      text-decoration: underline;
      text-underline-offset: 0.25em;
    }
  }
  .mk-collection-item-media {
    transition:
      scale 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
      filter 300ms ease,
      box-shadow 300ms ease;
  }
  .mk-collection-item-body {
    display: grid;
    gap: 0.125rem;
  }
  .mk-collection-item-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    & a {
      color: inherit;
      text-decoration: none;
    }
  }
  .mk-collection-item-count {
    margin: 0;
    color: var(--muted-foreground);
    font-size: 0.875rem;
  }
  .mk-collection-item-more {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-block-start: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
    & svg {
      width: 0.875rem;
      height: 0.875rem;
      transition: translate 150ms ease;
    }
  }
  .mk-collection-item:hover .mk-collection-item-more svg {
    translate: 0.25rem 0;
  }
  .mk-collection-item[data-variant="overlay"],
  .mk-collection-item[data-variant="banner"] {
    overflow: hidden;
    border-radius: var(--radius-xl);
    color: #fff;
    & .mk-collection-item-media {
      border-radius: 0;
    }
    &:hover .mk-collection-item-media {
      scale: 1.04;
      filter: none;
    }
    & .mk-collection-item-body {
      position: absolute;
      inset: auto 0 0;
      padding: 3rem 1.25rem 1.25rem;
      background: linear-gradient(transparent, oklch(0.12 0.02 260 / 0.8));
    }
    & .mk-collection-item-count {
      color: oklch(1 0 0 / 0.8);
    }
  }
  .mk-collection-item[data-variant="banner"] {
    & .mk-collection-item-media {
      aspect-ratio: 21 / 9;
    }
    & .mk-collection-item-body {
      inset: 0 auto 0 0;
      align-content: center;
      justify-items: start;
      width: min(100%, 26rem);
      padding: 2rem;
      background: linear-gradient(90deg, oklch(0.12 0.02 260 / 0.75), transparent);
    }
    & .mk-collection-item-title {
      font-size: clamp(1.5rem, 4vw, 2.25rem);
      letter-spacing: -0.03em;
    }
    & .mk-collection-item-more {
      margin-block-start: 1rem;
      padding: 0.5rem 1rem;
      border-radius: 999px;
      background: #fff;
      color: oklch(0.15 0 0);
    }
  }
  /* a short label over the picture: New, Bestseller, -20 % (data-tone="sale") */
  .mk-collection-item-badge {
    position: absolute;
    z-index: 1;
    inset: 0.75rem auto auto 0.75rem;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    background: var(--background);
    color: var(--foreground);
    box-shadow: var(--shadow-sm);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    pointer-events: none;
    &[data-tone="sale"] {
      background: #dc2626;
      color: #fff;
    }
  }
  /* overlay: a glass badge; the cue rises on hover or focus */
  .mk-collection-item[data-variant="overlay"] {
    & .mk-collection-item-badge:not([data-tone]) {
      border: 1px solid oklch(1 0 0 / 0.35);
      background: oklch(1 0 0 / 0.18);
      backdrop-filter: blur(8px);
      color: #fff;
      box-shadow: none;
    }
    & .mk-collection-item-more {
      opacity: 0;
      translate: 0 0.5rem;
      transition:
        opacity 200ms ease,
        translate 300ms cubic-bezier(0.2, 0.7, 0.2, 1);
    }
    &:is(:hover, :has(:focus-visible)) .mk-collection-item-more {
      opacity: 1;
      translate: 0 0;
    }
  }
  @media (hover: none) {
    .mk-collection-item[data-variant="overlay"] .mk-collection-item-more {
      opacity: 1;
      translate: 0 0;
    }
  }
  /* stack: three pictures of the collection as prints on a tinted panel; they fan out on hover or focus */
  .mk-collection-item[data-variant="stack"] {
    & .mk-collection-item-stack {
      display: grid;
      place-items: center;
      isolation: isolate;
      aspect-ratio: 5 / 4;
      padding: 1rem;
      overflow: hidden;
      border-radius: var(--radius-xl);
      background: var(--mk-collection-tint, var(--muted));
    }
    & .mk-collection-item-media {
      grid-area: 1 / 1;
      width: 46%;
      border: 0.25rem solid #fff;
      border-radius: var(--radius-lg);
      box-shadow: var(--shadow-md);
      transition:
        rotate 450ms cubic-bezier(0.2, 0.7, 0.2, 1),
        translate 450ms cubic-bezier(0.2, 0.7, 0.2, 1),
        scale 450ms cubic-bezier(0.2, 0.7, 0.2, 1);
    }
    & .mk-collection-item-media:nth-child(1) {
      rotate: -9deg;
      translate: -50% 5%;
    }
    & .mk-collection-item-media:nth-child(2) {
      rotate: 9deg;
      translate: 50% 5%;
    }
    /* the third print lies on top: the turned ones paint above an unturned one otherwise */
    & .mk-collection-item-media:nth-child(3) {
      z-index: 1;
    }
    &:is(:hover, :has(:focus-visible)) {
      & .mk-collection-item-media:nth-child(1) {
        rotate: -15deg;
        translate: -66% 9%;
      }
      & .mk-collection-item-media:nth-child(2) {
        rotate: 15deg;
        translate: 66% 9%;
      }
      & .mk-collection-item-media:nth-child(3) {
        scale: 1.08;
        translate: 0 -3%;
      }
    }
  }
  @media (prefers-reduced-motion: reduce) {
    .mk-collection-item,
    .mk-collection-item[data-variant="stack"] .mk-collection-item-media,
    .mk-collection-item[data-variant="overlay"] .mk-collection-item-more {
      transition: none;
    }
    .mk-collection-item:not([data-variant]):is(:hover, :has(:focus-visible)) {
      translate: none;
    }
  }
  /* -- Accessibility ------------------------------------------- */
  @media (prefers-reduced-motion: reduce) {
    .mk-collection-item-media,
    .mk-collection-item-more svg {
      transition: none;
    }
    .mk-collection-item:hover .mk-collection-item-media {
      scale: none;
    }
  }
  @media (forced-colors: active) {
    .mk-collection-item-badge {
      border: 1px solid CanvasText;
      background: Canvas;
      color: CanvasText;
    }
    .mk-collection-item:is([data-variant="overlay"], [data-variant="banner"]) .mk-collection-item-body {
      background: Canvas;
      color: CanvasText;
    }
  }
}

Comments, ideas or improvements? Edit this page's source on GitHub