Theme
On this page (4)
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

Data attributes

data-variant: overlay, banner.

§Grid

Default: a 4:5 picture, the collection name - a link covering the card - the count and a "Shop now" cue.

§Overlay

data-variant='overlay': the name over the picture with a scrim - the picture zooms a little on hover.

§Banner

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

§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(.2,.7,.2,1), filter 300ms ease; }
  .mk-collection-item:hover .mk-collection-item-media { filter: brightness(0.94); }
  .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); }
  }
  /* -- 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: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