全部效果滚动与入场

横向滚动展廊

Horizontal Scroll Gallery

卡片在自己的区域里左右移动,页面仍能正常上下滚动。

左右滑动或使用方向键

适用场景

适合在窄屏上浏览多个可视项目。 适合需要横向翻看的内容。露出下一张卡片的一小截,或提供前后翻页按钮,访客一眼就能知道可以继续看。

应用示例

用手机打开酒店详情时,住客可以左右滑动看房间照片,页面正文仍然能上下滚动。右侧露出下一张照片的一角,提示后面还有内容。

AI 提示词

为【目标位置】添加 Horizontal Scroll Gallery(横向滚动展廊)。用 flex 排列展廊,设置 overflow-x: auto 并允许键盘聚焦。保持卡片宽度稳定,露出后一张卡片的一部分作为线索。在减少动态效果模式下保持内容可读,并保留键盘操作。

示例代码

保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。

查看 HTML
<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>横向滚动展廊</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;
    }

    .scroll-panel {
      position: relative;
      width: min(100%, 215px);
      height: 133px;
      overflow: auto;
      overscroll-behavior: contain;
      scrollbar-width: thin;
      scrollbar-color: #9881cb #2e2540;
      border: 1px solid #806ca8;
      border-radius: 9px;
      background: #2d2342;
      color: #f5efff;
      font: 650 12px system-ui, sans-serif;
    }
    .scroll-panel p { margin: 0; }
    .scroll-panel hr { border: 0; margin: 6px 0; height: 5px; border-radius: 9px; background: #ae96dc4a; }
    .scroll-panel hr:nth-of-type(2n) { width: 72%; }
    .scroll-note { color: #ddcff1; text-align: center; font-size: 10px; }
    .scroll-panel:focus-visible { outline-offset: 2px; }
    @media (prefers-reduced-motion: reduce) {
      .scroll-panel, .scroll-panel *, .scroll-panel *::before, .scroll-panel *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
      }
    }

    .scroll-panel { display: flex; gap: 8px; align-items: stretch; height: 104px; padding: 8px; overflow-y: hidden; }
    .gallery-card {
      display: grid; flex: 0 0 118px; align-items: end; padding: 9px;
      border-radius: 7px; color: #f8efff; background: linear-gradient(135deg,#5e428a,#865b88);
    }
    .gallery-card:nth-child(2) { background: linear-gradient(135deg,#3e6c76,#354360); }
    .gallery-card:nth-child(3) { background: linear-gradient(135deg,#835266,#554073); }
  </style>
</head>
<body>
  <main class="demo">
    <div class="scroll-panel" role="region" tabindex="0" aria-label="横向展廊演示">
    <div class="gallery-card">色彩</div>
    <div class="gallery-card">字体</div>
    <div class="gallery-card">布局</div>
    </div>
  </main>
</body>
</html>

UI Skills 原创示例