Hover parent, animate child
Listen for hover on a still parent, and animate a child.
Emil Kowalski@emilkowalskiYou might've seen this bug before where the hover state keeps flickering. The fix is to separate the trigger from the effect. Listen for hovers on the parent, but animate a child element instead. This ensures that the hover area stays consistent.
From emil-design-eng; demo 1 rebuilds his post’s video.
Cards that lift on hover
Park the cursor at the edge, then raise Cursor past Lift.
Hover on the cardBad
Plan
Pro
$24 / mo
.card:hover { transform }0 entersHover on the parentGood
Plan
Pro
$24 / mo
.slot:hover .card { transform }0 enters<div class="card-slot">
<div class="card">…</div>
</div>
.card { transition: transform 200ms var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
.card-slot:hover .card { transform: translateY(-12px); }
}
@media (prefers-reduced-motion: reduce) {
.card-slot:hover .card { transform: none; }
}
Why it matters, pros and cons
Why it matters
Hover re-tests the moved box, so a moving trigger slips off the cursor.
Pros
- No flicker at any edge.
- Hit area matches what you see.
- Same pattern covers
:focus-visible.
Cons
- One extra wrapper or span per target.
- Unneeded for color, opacity or outward scale.