Stacked Service Cards on One Backdrop | Responsive CSS & React
No image assets: a services block that stacks explanation cards on a single backdrop. A dark plane carries the heading, an amber disc and three cards; each card changes its width, horizontal position and overlap with the previous one. The disc is centred on a corner of the card column and continues behind the cards. Around 375 px the heading sits in a 240 px visual and card 01 overlaps its lower edge by 40 px; from 768 px the heading and disc go left and the cards right. Under the preview, "Play the stacking order" and "Stack one by one" show the cards landing on the same backdrop. Motion uses only transform and opacity, and with reduced motion the finished state is shown from the start. The Code tab is the animated React + Tailwind CSS version with backdrop colour, card width, shift and overlap gathered in constants at the top, and the Latin font passed in through latinFontClassName. The HTML tab is a static version with no JavaScript and no font loading, tuned through CSS custom properties. Service names and copy are fictional samples.
Preview
Service
面は1枚。
そこに、積む。
写真1枚でも密度が出る構図。背景に、提供内容をずらして重ねます。
0 / 3 枚
Read the full description
No image assets: a services block that stacks explanation cards on a single backdrop. A dark plane carries the heading, an amber disc and three cards; each card changes its width, horizontal position and overlap with the previous one. The disc is centred on a corner of the card column and continues behind the cards. Around 375 px the heading sits in a 240 px visual and card 01 overlaps its lower edge by 40 px; from 768 px the heading and disc go left and the cards right. Under the preview, "Play the stacking order" and "Stack one by one" show the cards landing on the same backdrop. Motion uses only transform and opacity, and with reduced motion the finished state is shown from the start. The Code tab is the animated React + Tailwind CSS version with backdrop colour, card width, shift and overlap gathered in constants at the top, and the Latin font passed in through latinFontClassName. The HTML tab is a static version with no JavaScript and no font loading, tuned through CSS custom properties. Service names and copy are fictional samples.
- Added:
- 2026-08-17
- Updated:
- 2026-11-07
- Dependencies:
- None
- tags
- #block #service #stacked-cards #overlap #card-stack #responsive #container-query #replay #reduced-motion #no-image #react #tailwind #html-css
"use client";
import { useCallback, useEffect, useRef, useState } from "react";
// Next.js 以外へ移すときは、この import と下の defaultLatin を消し、latinFontClassName に自分のフォントの class を渡す
import { Montserrat } from "next/font/google";
const defaultLatin = Montserrat({
weight: ["500", "600", "700", "800"],
subsets: ["latin"],
display: "swap",
});
/* ─────────────────────────────────────────────────────────────
* 調整するのはここだけ(値はリテラルのクラス文字列で持つ。組み立てると Tailwind が拾わない)
*
* 幅ごとの配置方針(幅はこのブロックの幅。@container で判定する)
* - 375px 前後(〜559px): 見出しを背景の上部に載せて「ビジュアル」を高さ 240px に収め、
* カード01を下端に 40px 重ねる。カード01を右に寄せ、主形の円はその右上の角を中心に置く
* - 768px 前後(560〜719px): 左=見出しと円、右=カード列。円はカード列の左端を中心に置き、
* 見出しの下から始まり、右半分はカードの背後へ続く。背景の面はカード群の後ろまで1枚で敷く
* - 1280px 前後(720px〜): 768px と同じ組み方で、カードを少し大きく・ずらしを強くする
* ───────────────────────────────────────────────────────────── */
const LOOK = {
/** 背景の面(ビジュアルとカード群の後ろに1枚で敷く) */
plane: "bg-stone-900",
/** 主形(円)の色 */
disc: "bg-amber-500",
/** 補助(同心の細い円弧)の色 */
arc: "border-amber-300/25",
/** 番号の札(橙と濃色の焦点をカード番号に集める) */
badge: "bg-stone-900 text-amber-400",
};
/** カード1枚ずつの幅と横ずれ(素=375px / @min-[560px]=768px / @min-[720px]=1280px) */
const CARD_LAYOUT = [
"z-[1] ml-auto w-[88%] @min-[560px]:w-[94%] @min-[720px]:w-[90%]",
"z-[2] mr-auto w-[88%] @min-[560px]:mr-0 @min-[560px]:-ml-[16%] @min-[560px]:w-[96%] @min-[720px]:-ml-[22%] @min-[720px]:w-[94%]",
"z-[3] ml-[6%] w-[90%] @min-[560px]:ml-[6%] @min-[560px]:w-[92%] @min-[720px]:ml-[2%] @min-[720px]:w-[90%]",
];
/** 直前のカードへの重なり量。カード下端の余白(pb-5=20px / pb-7=28px)より小さくして本文を隠さない */
const CARD_OVERLAP = "-mt-3 @min-[560px]:-mt-5";
/** カード01がビジュアルの下端に重なる量(狭い幅だけ。広い幅は左右に組むので 0) */
const VISUAL_OVERLAP = "-mt-10 @min-[560px]:mt-0";
/** 再生のとき、1枚ごとに遅らせる時間(ms) */
const STAGGER_MS = 170;
type Service = {
idx: string;
en: string;
title: string;
body: string;
meta: string[];
href: string;
};
const DEFAULT_SERVICES: Service[] = [
{
idx: "01",
en: "Website",
title: "コーポレートサイト制作",
body: "情報設計からデザイン・実装まで一貫して担当します。公開後に更新しやすい構造で納めます。",
meta: ["情報設計", "デザイン", "実装"],
href: "#",
},
{
idx: "02",
en: "Landing Page",
title: "ランディングページ制作",
body: "問い合わせや購入など、目的の行動から逆算して構成とコピーを組みます。計測の設定まで含みます。",
meta: ["構成設計", "コピー", "計測設定"],
href: "#",
},
{
idx: "03",
en: "Operation",
title: "保守・改善運用",
body: "公開後もアクセスの数字を見ながら、更新と改善を続けます。月ごとに報告します。",
meta: ["保守", "改善提案", "月次報告"],
href: "#",
},
];
type Props = {
services?: Service[];
eyebrow?: string;
/** 欧文・数字に当てるフォントの class(next/font 以外のフォントもここで渡す) */
latinFontClassName?: string;
/** 見出しの要素。ページに h1 が既にあるなら既定の h2 のままでよい */
headingTag?: "h1" | "h2" | "p";
};
/** カードの出方。pre=まだ画面に入っていない / hidden=再生前に一瞬で戻した / playing=順に重ねる / stepping=1枚ずつ */
// pre = サーバーの HTML(JS の実行前)・armed = JS が動き、画面に入るのを待っている
type Mode = "pre" | "armed" | "hidden" | "playing" | "stepping";
/**
* サービス紹介の重ねるカードUI(1枚の背景×積層カード)
* サービス名・説明はすべて架空のサンプル。画像素材ゼロ・依存は React と Tailwind CSS だけ。
*
* 技法メモ:
* - 背景の面を1枚だけ敷き、見出し・主形(円)・カード群をすべてその上に置く。面を区切らないので「1枚に積む」が一目で伝わる
* - 主形の中心をカード列の角(狭い幅は右上・広い幅は左端)に合わせる。円はカードの背後へ続き、カードの隙間から見える
* - ずらすのは「幅」「横の位置」「直前との重なり」の3つ。重ね順は z-index、登場は transform と opacity だけで行い、レイアウトを動かさない
* - 動きを減らす設定では、最初から完成した状態を出す。再生・1枚ずつの操作は動きなしで切り替わる
*/
export default function ServicePhotoStack({
services = DEFAULT_SERVICES,
eyebrow = "Service",
latinFontClassName = defaultLatin.className,
headingTag,
}: Props) {
const Heading = headingTag ?? "h2";
const total = services.length;
const rootRef = useRef<HTMLElement>(null);
const [mode, setMode] = useState<Mode>("pre");
const [shown, setShown] = useState(0);
const frame = useRef(0);
const reduced = () =>
typeof window !== "undefined" &&
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
// 一度すべて隠してから、次の描画で目標の枚数まで出す(隠すときは transition を切る)
const runTo = useCallback(
(next: number, nextMode: Mode) => {
cancelAnimationFrame(frame.current);
if (reduced()) {
setMode(nextMode);
setShown(next);
return;
}
setMode("hidden");
setShown(0);
frame.current = requestAnimationFrame(() => {
frame.current = requestAnimationFrame(() => {
setMode(nextMode);
setShown(next);
});
});
},
[],
);
const play = useCallback(() => runTo(total, "playing"), [runTo, total]);
const step = () => {
if (shown >= total || mode === "pre" || mode === "armed") {
runTo(1, "stepping");
return;
}
setMode("stepping");
setShown((n) => Math.min(total, n + 1));
};
// 画面に入ったら1度だけ再生(IntersectionObserver が無い環境はすぐ完成状態にする)
useEffect(() => {
const node = rootRef.current;
// JS が動いたので、時間切れで出す仕掛け(下の svc-failsafe)を外して画面に入るのを待つ
const armId = requestAnimationFrame(() => setMode((m) => (m === "pre" ? "armed" : m)));
if (!node || typeof IntersectionObserver === "undefined") {
const id = requestAnimationFrame(() => {
setMode("playing");
setShown(total);
});
return () => cancelAnimationFrame(id);
}
const io = new IntersectionObserver(
(entries) => {
if (entries.some((e) => e.isIntersecting)) {
play();
io.disconnect();
}
},
{ threshold: 0.15 },
);
io.observe(node);
return () => {
cancelAnimationFrame(armId);
io.disconnect();
cancelAnimationFrame(frame.current);
};
}, [play, total]);
const instant = mode === "hidden";
const motion = instant
? "transition-none"
: "transition-[opacity,transform] duration-500 ease-[cubic-bezier(0.2,0.7,0.2,1)] motion-reduce:transition-none";
// まだ画面に入っていない間も、動きを減らす設定なら完成状態で見せる。
// JS の実行前(pre)は JS が有効な環境だけ隠し、JS が固まっても 2.5 秒で出す(本文が見えないままにしない)。
// Tailwind v4 の translate-*/scale-* は transform ではなく translate/scale の個別プロパティなので、出す側もそれを戻す
const waiting = mode === "pre" || mode === "armed";
const hiddenCard =
mode === "pre"
? "[@media(scripting:enabled)]:translate-y-8 [@media(scripting:enabled)]:opacity-0 [@media(scripting:enabled)]:animate-[svc-failsafe_0s_2.5s_forwards] motion-reduce:translate-y-0 motion-reduce:opacity-100"
: mode === "armed"
? "translate-y-8 opacity-0 motion-reduce:translate-y-0 motion-reduce:opacity-100"
: "translate-y-8 opacity-0";
const discOn = waiting ? false : shown > 0 || mode === "stepping";
const status = `${shown} / ${total} 枚`;
return (
<section
ref={rootRef}
aria-labelledby="svc-stack-heading"
className="@container w-full max-w-5xl bg-white px-1"
>
<style>{"@keyframes svc-failsafe{to{opacity:1;translate:none}}@keyframes svc-failsafe-disc{to{opacity:1;scale:1}}"}</style>
{/* 背景の面(1枚)。見出し・主形・カード群をすべてこの上に置く */}
<div
className={`relative isolate overflow-hidden rounded-sm ${LOOK.plane} px-4 pt-5 pb-6 @min-[560px]:grid @min-[560px]:grid-cols-12 @min-[560px]:px-7 @min-[560px]:py-9 @min-[720px]:px-10 @min-[720px]:py-11`}
>
{/* ビジュアル(見出しを載せた面の上部。狭い幅は上の余白と合わせて高さ 240px・広い幅は左の列) */}
<header className="relative z-[1] min-h-[220px] pr-[30%] @min-[560px]:col-span-5 @min-[560px]:row-start-1 @min-[560px]:min-h-0 @min-[560px]:pr-6">
<p
className={`${latinFontClassName} flex items-center gap-3 text-[11px] font-bold tracking-[0.28em] text-amber-400 uppercase`}
>
<span aria-hidden="true" className="block h-px w-6 bg-amber-400" />
{eyebrow}
</p>
<Heading
id="svc-stack-heading"
className="mt-4 text-[clamp(1.6rem,6.4cqw,2.5rem)] leading-[1.3] font-bold tracking-tight text-white @min-[560px]:text-[clamp(1.7rem,4.6cqw,2.5rem)]"
>
面は1枚。
<br />
そこに、積む。
</Heading>
<p className="mt-4 text-[13px] leading-[1.85] font-medium text-stone-300 [word-break:auto-phrase] @min-[560px]:text-[14px] @min-[720px]:max-w-[22em]">
写真1枚でも密度が出る構図。背景に、提供内容をずらして重ねます。
</p>
</header>
{/* 積層カード。円と円弧はこの列の角を中心に置き、カードの背後へ続ける */}
<div
className={`relative mt-0 ${VISUAL_OVERLAP} @min-[560px]:col-span-7 @min-[560px]:col-start-6 @min-[560px]:row-span-2 @min-[560px]:row-start-1 @min-[560px]:mt-14 @min-[720px]:mt-16`}
>
{/* 装飾は ol の外に置く(ol の項目に数えさせない) */}
<div aria-hidden="true" className="contents">
{/* 主形: 円。狭い幅はカード01の右上の角・広い幅はカード列の左端(見出しより下)が中心 */}
<span
className={`pointer-events-none absolute top-0 right-0 -z-10 block size-[220px] translate-x-1/2 -translate-y-1/2 rounded-full ${LOOK.disc} ${motion} @min-[560px]:top-[44%] @min-[560px]:right-auto @min-[560px]:left-0 @min-[560px]:size-[clamp(240px,44cqw,360px)] @min-[560px]:-translate-x-1/2 ${
discOn
? "scale-100 opacity-100"
: mode === "pre"
? "[@media(scripting:enabled)]:scale-75 [@media(scripting:enabled)]:opacity-0 [@media(scripting:enabled)]:animate-[svc-failsafe-disc_0s_2.5s_forwards] motion-reduce:scale-100 motion-reduce:opacity-100"
: mode === "armed"
? "scale-75 opacity-0 motion-reduce:scale-100 motion-reduce:opacity-100"
: "scale-75 opacity-0"
}`}
/>
{/* 補助: 同じ中心の細い円弧(2本) */}
<span
className={`pointer-events-none absolute top-0 right-0 -z-10 block size-[360px] translate-x-1/2 -translate-y-1/2 rounded-full border ${LOOK.arc} @min-[560px]:top-[44%] @min-[560px]:right-auto @min-[560px]:left-0 @min-[560px]:size-[clamp(400px,74cqw,600px)] @min-[560px]:-translate-x-1/2`}
/>
<span
className={`pointer-events-none absolute top-0 right-0 -z-10 block size-[500px] translate-x-1/2 -translate-y-1/2 rounded-full border ${LOOK.arc} @min-[560px]:top-[44%] @min-[560px]:right-auto @min-[560px]:left-0 @min-[560px]:size-[clamp(560px,104cqw,840px)] @min-[560px]:-translate-x-1/2`}
/>
</div>
<ol className="flex list-none flex-col pl-0">
{services.map((s, i) => {
const on = i < shown;
return (
<li
key={s.idx}
inert={!on && !waiting}
className={`group relative hover:z-10 ${CARD_LAYOUT[i % CARD_LAYOUT.length]} ${i > 0 ? CARD_OVERLAP : ""} ${motion} ${
on ? "translate-y-0 opacity-100" : hiddenCard
}`}
style={{ transitionDelay: mode === "playing" ? `${120 + i * STAGGER_MS}ms` : "0ms" }}
>
<div className="relative rounded-sm bg-white px-4 pt-4 pb-5 shadow-[0_24px_40px_-24px_rgba(0,0,0,0.65)] transition-transform duration-300 ease-out group-hover:-translate-y-1 motion-reduce:transition-none @min-[560px]:px-6 @min-[720px]:px-8 @min-[720px]:pt-7 @min-[720px]:pb-7">
{/* 番号の札 + 英語ラベル + 罫線 */}
<div className="flex items-center gap-3">
<span
className={`${latinFontClassName} ${LOOK.badge} inline-flex h-8 min-w-8 items-center justify-center px-1.5 text-[13px] font-extrabold tracking-[0.08em] tabular-nums`}
>
{s.idx}
</span>
<span
className={`${latinFontClassName} text-[11px] font-semibold tracking-[0.2em] text-stone-500 uppercase`}
>
{s.en}
</span>
<span
aria-hidden="true"
className="h-px flex-1 bg-stone-200 transition-colors duration-300 group-hover:bg-amber-500/60 motion-reduce:transition-none"
/>
</div>
<h3 className="mt-3 text-[18px] leading-[1.5] font-bold tracking-tight text-stone-900 @min-[720px]:mt-4 @min-[720px]:text-[21px]">
{s.title}
</h3>
<p className="mt-2 text-[13.5px] leading-[1.85] font-medium text-stone-600 @min-[720px]:mt-3 @min-[720px]:text-[14px]">
{s.body}
</p>
<div className="mt-3 flex flex-wrap items-center gap-x-2 gap-y-1 border-t border-stone-200 pt-3 text-[11px] font-semibold text-stone-500 @min-[720px]:mt-4 @min-[720px]:gap-x-3">
{s.meta.map((m, mi) => (
<span key={m} className="flex items-center gap-2 @min-[720px]:gap-3">
{mi > 0 && (
<span aria-hidden="true" className="text-stone-300">
/
</span>
)}
{m}
</span>
))}
<a
href={s.href}
className="ml-auto inline-flex min-h-6 items-center gap-2 text-[12px] font-bold text-stone-900 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-amber-600"
>
<span className="relative">
詳しく見る
<span
aria-hidden="true"
className="absolute -bottom-1 left-0 h-px w-full origin-left scale-x-100 bg-stone-900 transition-transform duration-300 ease-out group-hover:scale-x-0 motion-reduce:transition-none"
/>
<span
aria-hidden="true"
className="absolute -bottom-1 left-0 h-px w-full origin-right scale-x-0 bg-amber-600 transition-transform delay-150 duration-300 ease-out group-hover:origin-left group-hover:scale-x-100 motion-reduce:transition-none"
/>
</span>
<span
aria-hidden="true"
className="inline-block transition-transform duration-300 ease-out group-hover:translate-x-1 motion-reduce:transition-none"
>
→
</span>
</a>
</div>
</div>
</li>
);
})}
</ol>
</div>
{/* 広い幅だけ、左の列の下に縦組みのラベルを置く(円の左側の余白を締める) */}
<p
aria-hidden="true"
className={`${latinFontClassName} hidden self-end text-[10px] font-semibold tracking-[0.35em] text-stone-500 uppercase [writing-mode:vertical-rl] @min-[560px]:col-span-1 @min-[560px]:col-start-1 @min-[560px]:row-start-2 @min-[560px]:block`}
>
One plane / {total} cards
</p>
</div>
{/* 再生の操作(プレビューの直下) */}
<div className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-2">
<button
type="button"
onClick={play}
className="inline-flex min-h-11 items-center gap-2 rounded-sm bg-stone-900 px-4 text-[13px] font-bold text-white transition-colors hover:bg-stone-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-600"
>
<span aria-hidden="true" className="text-amber-400">
▶
</span>
重なる順に再生
</button>
<button
type="button"
onClick={step}
className="inline-flex min-h-11 items-center gap-2 rounded-sm border border-stone-300 bg-white px-4 text-[13px] font-bold text-stone-800 transition-colors hover:border-stone-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-600"
>
1枚ずつ重ねる
</button>
<div className="flex items-center gap-2" aria-hidden="true">
{services.map((s, i) => (
<span
key={s.idx}
className={`block h-1.5 w-6 origin-left ${instant ? "transition-none" : "transition-transform duration-300 motion-reduce:transition-none"} ${
i < shown ? "scale-x-100 bg-amber-500" : "scale-x-[0.25] bg-stone-300"
}`}
style={{ transitionDelay: mode === "playing" ? `${120 + i * STAGGER_MS}ms` : "0ms" }}
/>
))}
</div>
<p
aria-live="polite"
className={`${latinFontClassName} text-[12px] font-semibold text-stone-500 tabular-nums`}
>
{status}
</p>
</div>
{/* 注記と出典 */}
<div className="mt-6 space-y-1 text-[11px] leading-[1.8] text-stone-500">
<p>
掲載しているサービス名・説明はサンプルです。件数は3〜4件までが読みやすく、5件以上では一覧性のある構成を選びます。
</p>
<p>
動きを減らす設定で動きを止める根拠: W3C「Understanding SC 2.3.3: Animation from Interactions」(WCAG 2.2・レベルAAA。prefers-reduced-motion は十分な技法 C39)
<a
href="https://www.w3.org/WAI/WCAG22/Understanding/animation-from-interactions.html"
className="ml-1 underline underline-offset-2 hover:text-stone-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-600"
>
w3.org
</a>
。操作ボタンの大きさ: 同「SC 2.5.8: Target Size (Minimum)」の 24×24 CSS px 以上(どちらも 2026-11-06 確認)
<a
href="https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html"
className="ml-1 underline underline-offset-2 hover:text-stone-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-600"
>
w3.org
</a>
。
</p>
</div>
</section>
);
}
Add to your project via shadcn CLI
npx shadcn@latest add https://designs.first-ch.com/r/service-photo-stack.json