07호버 시 grid span 확장
타일이 이웃 칸까지 넓어져 보이게 하려 했지만 grid-column: span 값 자체는 트랜지션이 걸리지 않아, 실제로는 transform: scale과 z-index로 옆 칸 위에 포개는 방식으로 확장을 흉내 냅니다.
쓰임그리드에서 한 칸만 강조해 크게 보고 싶은 대시보드, 카탈로그 타일
scalez-indextransform-origin: top left

<main class="stage">
<div class="he-grid is-demo">
<div class="he-tile he-focal">
<span class="he-tile__tag">Live</span>
<span class="he-tile__num">128</span>
</div>
<div class="he-tile">
<span class="he-tile__tag">Users</span>
</div>
<div class="he-tile">
<span class="he-tile__tag">Sessions</span>
</div>
<div class="he-tile">
<span class="he-tile__tag">Errors</span>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-enter;
$easing: $ease-spring;
$scale: 1.35;
@include stage($stage-orange);
.he-grid {
width: min(320px, 88vw);
aspect-ratio: 340 / 190;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: $sp-2;
}
.he-tile {
border-radius: $r-sm;
padding: $sp-3;
box-sizing: border-box;
color: $subject-cream;
background: rgba(23, 20, 26, .55);
font: 600 12px/1 -apple-system, "Segoe UI", sans-serif;
display: flex;
flex-direction: column;
justify-content: flex-end;
position: relative;
transform-origin: top left; // 규칙8: 그리드 좌상단 칸 안쪽 확장
}
.he-focal { background: $subject-ink; }
.he-tile__tag { opacity: .8; }
.he-tile__num { font-size: 24px; font-weight: 700; margin-top: $sp-1; }
// grid-column/row 의 span 값 자체는 트랜지션이 걸리지 않는다(이산값이라 중간 프레임이 없다) —
// 그래서 실제 칸 배치는 그대로 두고 transform: scale + z-index 로 옆 칸을 덮어 "확장"을 흉내 낸다
.he-focal {
transition: transform $duration $easing, box-shadow $duration $easing;
box-shadow: $shadow-press;
}
.he-focal:hover {
transform: scale($scale);
box-shadow: $shadow-raised;
z-index: 5;
}
@keyframes he-expand {
0%, 100% { transform: scale(1); box-shadow: $shadow-press; z-index: 1; }
50% { transform: scale($scale); box-shadow: $shadow-raised; z-index: 5; }
}
.he-grid.is-demo .he-focal { animation: he-expand $duration $easing infinite; }
@media (prefers-reduced-motion: reduce) {
.he-focal:hover,
.he-grid.is-demo .he-focal { animation: none !important; transform: none !important; box-shadow: $shadow-press !important; z-index: 1 !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ff4d1f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.he-grid {
width: min(320px, 88vw);
aspect-ratio: 340/190;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: 8px;
}
.he-tile {
border-radius: 8px;
padding: 12px;
box-sizing: border-box;
color: #fff7e6;
background: rgba(23, 20, 26, 0.55);
font: 600 12px/1 -apple-system, "Segoe UI", sans-serif;
display: flex;
flex-direction: column;
justify-content: flex-end;
position: relative;
transform-origin: top left;
}
.he-focal {
background: #17141a;
}
.he-tile__tag {
opacity: 0.8;
}
.he-tile__num {
font-size: 24px;
font-weight: 700;
margin-top: 4px;
}
.he-focal {
transition: transform 600ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 600ms cubic-bezier(0.2, 0.8, 0.2, 1);
box-shadow: 0 6px 12px rgba(23, 20, 26, 0.32);
}
.he-focal:hover {
transform: scale(1.35);
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
z-index: 5;
}
@keyframes he-expand {
0%, 100% {
transform: scale(1);
box-shadow: 0 6px 12px rgba(23, 20, 26, 0.32);
z-index: 1;
}
50% {
transform: scale(1.35);
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
z-index: 5;
}
}
.he-grid.is-demo .he-focal {
animation: he-expand 600ms cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
}
@media (prefers-reduced-motion: reduce) {
.he-focal:hover,
.he-grid.is-demo .he-focal {
animation: none !important;
transform: none !important;
box-shadow: 0 6px 12px rgba(23, 20, 26, 0.32) !important;
z-index: 1 !important;
}
}import { CSSProperties } from "react";
import styles from "./HoverExpandSpan.module.scss";
type Vars = CSSProperties & {
"--duration"?: string;
"--easing"?: string;
"--scale"?: number;
};
export interface HoverExpandSpanProps {
duration?: string;
easing?: string;
scale?: number;
}
// grid-column/row 의 span 값은 트랜지션이 걸리지 않아 transform: scale + z-index 로 확장을 흉내 낸다
export default function HoverExpandSpan({
duration = "600ms",
easing = "cubic-bezier(.2, .8, .2, 1)",
scale = 1.35,
}: HoverExpandSpanProps) {
const style: Vars = {
"--duration": duration,
"--easing": easing,
"--scale": scale,
};
return (
<div className={styles.grid} style={style}>
<div className={`${styles.tile} ${styles.focal}`}>
<span className={styles.tag}>Live</span>
<span className={styles.num}>128</span>
</div>
<div className={styles.tile}>
<span className={styles.tag}>Users</span>
</div>
<div className={styles.tile}>
<span className={styles.tag}>Sessions</span>
</div>
<div className={styles.tile}>
<span className={styles.tag}>Errors</span>
</div>
</div>
);
}07 호버 시 grid span 확장 — 측정 누적면적 13.703% · 움직인 프레임 23/23GODRICH 원작 · zip 에 SCSS·React 포함 · 벤토 그리드 레이아웃 호버 애니메이션 9종
이 데모가 속한 글
벤토 그리드 레이아웃 호버 애니메이션 9종포트폴리오나 제품 소개 페이지에서 크고 작은 네모 칸이 사진 콜라주처럼 이어 붙은 레이아웃을 본 적 있으신가요? 이런 벤토 그리드 레이아웃에 마우스를 올렸을 때 칸마다 살짝 반응하게 만드는 CSS 코드를 아홉 가지로 이 글의 데모 전부 보기


