Expanding Panels
Five vertical panels of layered CSS-gradient 'artwork', one per spectrum hue. Focusing or hovering a panel lets it flex-grow to fill most of the row while its siblings compress; a :has() on the row dims the ones you left behind. Fully keyboard-operable via real buttons.
- flex-grow transition
- :focus-within
- :has()
- layered gradients
Source
A single self-contained .astro component. It uses Prism's design tokens (--spectrum-*, --ink…) with sensible fallbacks, so it renders even outside this site.
---
export const meta = {
title: "Expanding Panels",
tags: ["gallery", "flex", "hover", "accordion"],
description:
"Five vertical panels of layered CSS-gradient 'artwork', one per spectrum hue. Focusing or hovering a panel lets it flex-grow to fill most of the row while its siblings compress; a :has() on the row dims the ones you left behind. Fully keyboard-operable via real buttons.",
tech: ["flex-grow transition", ":focus-within", ":has()", "layered gradients"],
height: 460,
};
const panels = [
{ hue: "var(--spectrum-1, #8b5cf6)", label: "Violet", kicker: "01", title: "Nebula" },
{ hue: "var(--spectrum-2, #5b8def)", label: "Blue", kicker: "02", title: "Meridian" },
{ hue: "var(--spectrum-3, #45d3e8)", label: "Cyan", kicker: "03", title: "Tidewater" },
{ hue: "var(--spectrum-4, #3ddc97)", label: "Green", kicker: "04", title: "Verdigris" },
{ hue: "var(--spectrum-5, #fbbf24)", label: "Amber", kicker: "05", title: "Solstice" },
];
---
<section class="ep">
<ul class="ep__row" role="list">
{panels.map((p) => (
<li class="ep__item">
<a
href="#"
class="ep__panel"
style={`--hue:${p.hue}`}
aria-label={`${p.title} — ${p.label} artwork`}
>
<span class="ep__art" aria-hidden="true"></span>
<span class="ep__grain" aria-hidden="true"></span>
<span class="ep__caption">
<span class="ep__kicker">{p.kicker}</span>
<span class="ep__title">{p.title}</span>
<span class="ep__label">{p.label}</span>
</span>
</a>
</li>
))}
</ul>
</section>
<style>
.ep {
min-height: 460px;
display: grid;
place-items: center;
padding: clamp(1.5rem, 1rem + 2vw, 3rem) var(--gutter, 1.5rem);
background: var(--bg-sunk, #0b0c15);
}
.ep__row {
list-style: none;
margin: 0;
padding: 0;
display: flex;
gap: clamp(0.4rem, 0.2rem + 0.6vw, 0.9rem);
width: 100%;
max-width: var(--container-wide, 80rem);
height: clamp(20rem, 16rem + 12vw, 24rem);
}
.ep__item {
display: flex;
flex: 1 1 0;
min-width: 0;
/* the growth animation lives here so the whole cell participates */
transition: flex-grow var(--dur-slow, 0.6s) var(--ease-emph, cubic-bezier(0.2, 0, 0, 1));
}
/* the focused/hovered panel's cell claims most of the row */
.ep__item:has(.ep__panel:hover),
.ep__item:has(.ep__panel:focus-visible) {
flex-grow: 5;
}
.ep__panel {
position: relative;
flex: 1;
min-width: 0;
display: block;
border-radius: var(--radius-l, 20px);
overflow: hidden;
text-decoration: none;
isolation: isolate;
box-shadow: var(--shadow-m, 0 10px 30px rgba(0, 0, 0, 0.25));
transition: filter var(--dur, 0.32s) var(--ease-out, ease),
transform var(--dur, 0.32s) var(--ease-out, ease);
}
/* the layered gradient "artwork" — tinted by each panel's --hue */
.ep__art {
position: absolute;
inset: 0;
z-index: -2;
background:
radial-gradient(120% 80% at 20% 0%, color-mix(in oklab, var(--hue) 85%, white 10%), transparent 60%),
radial-gradient(100% 90% at 90% 100%, color-mix(in oklab, var(--hue) 70%, black 30%), transparent 65%),
conic-gradient(from 210deg at 65% 40%, color-mix(in oklab, var(--hue) 60%, black 20%), color-mix(in oklab, var(--hue) 95%, white 5%), color-mix(in oklab, var(--hue) 50%, black 35%));
transition: transform var(--dur-slow, 0.6s) var(--ease-emph, cubic-bezier(0.2, 0, 0, 1));
}
/* faint diagonal sheen for depth */
.ep__grain {
position: absolute;
inset: 0;
z-index: -1;
background:
repeating-linear-gradient(115deg, transparent 0 9px, color-mix(in oklab, black 12%, transparent) 9px 10px),
linear-gradient(to top, color-mix(in oklab, black 55%, transparent), transparent 55%);
mix-blend-mode: soft-light;
opacity: 0.7;
}
.ep__panel:hover .ep__art,
.ep__panel:focus-visible .ep__art { transform: scale(1.06); }
.ep__caption {
position: absolute;
inset: auto 0 0 0;
display: grid;
gap: 0.15rem;
padding: clamp(0.7rem, 0.5rem + 0.8vw, 1.2rem);
color: #fff;
}
.ep__kicker {
font-family: var(--font-mono, monospace);
font-size: var(--step--1, 0.8rem);
letter-spacing: 0.15em;
opacity: 0.75;
}
.ep__title {
font-size: var(--step-2, 1.6rem);
font-weight: 680;
letter-spacing: -0.02em;
line-height: 1.05;
/* keep long titles from wrapping while a panel is collapsed */
white-space: nowrap;
}
.ep__label {
font-size: var(--step--1, 0.85rem);
color: rgba(255, 255, 255, 0.82);
max-height: 0;
opacity: 0;
overflow: hidden;
transition: max-height var(--dur, 0.32s) var(--ease-out, ease),
opacity var(--dur, 0.32s) var(--ease-out, ease);
}
.ep__panel:hover .ep__label,
.ep__panel:focus-visible .ep__label {
max-height: 2rem;
opacity: 1;
}
/* dim the panels you're not engaging with */
.ep__row:has(.ep__panel:hover) .ep__item:not(:has(.ep__panel:hover)) .ep__panel,
.ep__row:has(.ep__panel:focus-visible) .ep__item:not(:has(.ep__panel:focus-visible)) .ep__panel {
filter: brightness(0.72) saturate(0.9);
}
/* On narrow screens, stack into a scrollable rail with sensible sizes */
@media (max-width: 640px) {
.ep__row { height: auto; flex-wrap: wrap; }
.ep__item { flex: 1 1 40%; }
.ep__item:has(.ep__panel:hover),
.ep__item:has(.ep__panel:focus-visible) { flex-grow: 1; }
.ep__panel { aspect-ratio: 3 / 4; }
.ep__label { max-height: 2rem; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
.ep__item,
.ep__panel,
.ep__art,
.ep__label { transition: none; }
}
</style>