StealThis .dev
Patterns Medium

Card Grid Transition

Shared-element transition from a card grid to a detail page using the View Transitions API.

Open in Lab
view-transitions-apicss
Targets: JS HTML

Code

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #070a12;
  --panel: #121a2b;
  --border: #263249;
  --text: #f0f4fb;
  --muted: #8a95a8;
  --accent: #86e8ff;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'SF Pro Display', system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Views ── */
.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: block;
}

/* ── Page header ── */
.page-header {
  text-align: center;
  padding: 5rem 2rem 2rem;
}

.eyebrow {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  margin-bottom: 1rem;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  color: var(--muted);
  max-width: 480px;
  margin: 0.75rem auto 0;
  line-height: 1.6;
}

/* ── Card grid ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 2rem 4rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-4px);
  border-color: rgba(134, 232, 255, 0.3);
  box-shadow: 0 8px 32px rgba(134, 232, 255, 0.06);
}

.card-visual {
  position: relative;
  height: 180px;
  overflow: hidden;
}

.card-image {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    hsl(var(--hue, 200) 60% 15%),
    hsl(var(--hue, 200) 80% 25%),
    hsl(calc(var(--hue, 200) + 40) 70% 20%)
  );
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-number {
  font-size: 3rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.15);
  letter-spacing: -0.03em;
}

.card-body {
  padding: 1.25rem;
}

.card-body h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.card-body p {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Detail view ── */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}

.detail-image-area {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.detail-image {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, hsl(200 60% 15%), hsl(200 80% 25%), hsl(240 70% 20%));
}

.detail-number {
  font-size: 8rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.1);
  letter-spacing: -0.03em;
}

.detail-content {
  padding: 4rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.back-btn {
  align-self: flex-start;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--accent);
  padding: 0.5rem 1rem;
  font: 600 0.8rem/1 'Inter', system-ui, sans-serif;
  cursor: pointer;
  transition: border-color 0.25s, background 0.25s;
}

.back-btn:hover {
  border-color: var(--accent);
  background: rgba(134, 232, 255, 0.06);
}

.detail-title {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.detail-desc {
  font-size: 1.1rem;
  color: var(--muted);
  line-height: 1.6;
}

.detail-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.meta-tag {
  padding: 0.25rem 0.7rem;
  background: rgba(134, 232, 255, 0.1);
  border: 1px solid rgba(134, 232, 255, 0.2);
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-body {
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.7;
}

.detail-body code {
  background: rgba(134, 232, 255, 0.1);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--accent);
}

/* ── View Transition styles ── */
::view-transition-old(root) {
  animation: fade-out 0.25s ease-out;
}

::view-transition-new(root) {
  animation: fade-in 0.25s ease-in;
}

::view-transition-group(card-image-1),
::view-transition-group(card-image-2),
::view-transition-group(card-image-3),
::view-transition-group(card-image-4),
::view-transition-group(card-image-5),
::view-transition-group(card-image-6) {
  animation-duration: 0.4s;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

::view-transition-group(card-title-1),
::view-transition-group(card-title-2),
::view-transition-group(card-title-3),
::view-transition-group(card-title-4),
::view-transition-group(card-title-5),
::view-transition-group(card-title-6) {
  animation-duration: 0.35s;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Fallback for no View Transitions ── */
.no-vt .view {
  transition: opacity 0.3s ease;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .detail-image-area {
    position: relative;
    height: 50vh;
  }

  .detail-content {
    padding: 2rem 1.5rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
    padding: 0 1rem 3rem;
  }
}

Card Grid Transition

Shared-element transition from a card grid to a detail page using the View Transitions API.

Source

  • Repository: libs-genclaude
  • Original demo id: 11-card-detail-transition

Notes

Shared-element transition from a card grid to a detail page using the View Transitions API.