All effectsHover & follow

Hover Panel Expansion

悬停面板联动扩展

The active panel gains width as its neighbors narrow within a fixed row.

Move the pointer, tap, or use the keyboard

Where to use it

Build an immersive project shelf or a compact feature comparison. Use a short row of panels with essentials visible at their narrowest width. On mobile, give each panel room and offer a tap action.

Practical example

On a destination guide, hovering over the coast panel widens its scenic photo while the forest and city panels narrow. Their destination names remain visible so visitors can switch easily.

AI prompt

Add Hover Panel Expansion to [target]. Animate a small fixed grid’s fractional track sizes. Toggle one active panel on tap, mirror keyboard focus, and keep each neighboring panel at a usable minimum width. Keep the controls keyboard accessible and provide a reduced-motion state.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Hover Panel Expansion</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .panel-row { display:grid; grid-template-columns:1fr 1fr 1fr; gap:4px; width:min(100%,280px); height:clamp(106px,68vh,174px); transition:grid-template-columns 350ms cubic-bezier(.22,.71,.23,1); }
    .panel-row[data-choice="0"] { grid-template-columns:2.6fr 1fr 1fr; }
    .panel-row[data-choice="1"] { grid-template-columns:1fr 2.6fr 1fr; }
    .panel-row[data-choice="2"] { grid-template-columns:1fr 1fr 2.6fr; }
    .panel-row button { min-width:0; display:grid; align-items:end; justify-items:center; padding:7px 3px; background:radial-gradient(ellipse at 70% 27%,#f5d6f4,transparent 45%),linear-gradient(138deg,#6b5791,#343b68); border:1px solid #c8a8e668; color:#fff; border-radius:9px; font-weight:700; cursor:pointer; }
    .panel-row button:nth-child(2) { background:radial-gradient(ellipse at 42% 20%,#eaf9a9,transparent 48%),linear-gradient(132deg,#739b64,#415242); }
    .panel-row button:nth-child(3) { background:radial-gradient(ellipse at 46% 20%,#a0ffed,transparent 48%),linear-gradient(136deg,#387888,#18546b); }
    .panel-row span { padding:3px 5px; background:#152337e5; border-radius:4px; font-size:11px; }

    @media (prefers-reduced-motion: reduce) {
      .lab, .lab *, .lab::before, .lab::after, .lab *::before, .lab *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
      }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="lab panel-row" aria-label="Flexible panels">
    <button type="button" data-panel="0" aria-pressed="false"><span>Air</span></button><button type="button" data-panel="1" aria-pressed="false"><span>Land</span></button><button type="button" data-panel="2" aria-pressed="false"><span>Sea</span></button>
    </div>
  </main>
  <script>
    const row = document.querySelector('.panel-row');
    const buttons = [...row.querySelectorAll('button')];
    let selected = '';
    function show(value) { row.dataset.choice = value; }
    buttons.forEach((button) => {
      button.addEventListener('pointerenter', (event) => { if (event.pointerType !== 'touch') show(button.dataset.panel); });
      button.addEventListener('focus', () => show(button.dataset.panel));
      button.addEventListener('click', () => {
        selected = selected === button.dataset.panel ? '' : button.dataset.panel;
        buttons.forEach((candidate) => candidate.setAttribute('aria-pressed', String(candidate.dataset.panel === selected)));
        show(selected);
      });
    });
    row.addEventListener('pointerleave', () => show(selected));
    row.addEventListener('focusout', (event) => { if (!row.contains(event.relatedTarget)) show(selected); });
  </script>
</body>
</html>

Original example by UI Skills

Further examples