中文
作品全部 3
海报2026记账小程序2025品牌手册2025
Hover & pointer · CSS only

Hover lift

悬停上浮

Lift a card slightly on hover.

Also searched as: 鼠标放上去,卡片往上浮一点, 卡片悬停时抬起来,影子变深, 鼠标经过时卡片浮起来, 悬浮抬升

AI Markdown (.md)
Placement
Card list, Button
Mood
Crisp
Trigger
悬停
Site types
个人网站, 作品集, 博客

How it works & accessibility

On hover and focus, translate the card upward and soften its shadow without affecting document layout.

Best for: Card list, Button (悬停).

Reduced motion: 照样浮起来、影子变深,但不做过渡,直接到位

Mobile & touch: 手机上没有悬停:不浮起来(只在能悬停的设备上生效,免得点一下以后卡片一直停在浮起的样子),点一下照常打开;键盘选中时照样浮起来

Key parameters

ParameterKeyDefaultRangeNotes
上浮距离distance4px——
时长duration200ms——
缓动easingcubic-bezier(0.33, 1, 0.68, 1)——

Ready-to-paste AI prompt

Add “Hover lift” to the card list in my project: On hover and focus, translate the card upward and soften its shadow without affecting document layout.
Parameters: distance: 4px, duration: 200ms, easing: cubic-bezier(0.33, 1, 0.68, 1).
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/hover-lift.md (canonical specification and reference code).

Dependency-free reference code

CSS
/* 悬停上浮(Hover lift)· 只用 CSS,不需要脚本。
   改写自 StyleKit 的 hover-lift(MIT License,Copyright (c) 2026 AnxForever):动作、默认值和浮起时的影子来自它;
   悬停只在能悬停的设备上生效、键盘选中时也浮起来,学 Animation Handbook 的 hover-state(MIT License,Copyright (c) 2026 Matin Monshizadeh)。
   给卡片(或按钮)加上 class="lift"。鼠标停上去、键盘选中时,往上浮 --lift-distance,影子换成 --lift-shadow;离开时落回原位。
   - 用 translate 属性,不盖掉卡片原来的 transform;原来的影子在不浮的时候照旧。卡片原来就用 translate 属性挪过位置的,浮起来时要把那一段加进去。
   - 悬停只在能悬停的设备上生效:手机点一下以后 :hover 会一直留着,卡片就一直浮着。键盘选中(:focus-visible)不分设备。
     卡片本身不能用键盘选中、里面的链接能的,里面的链接被选中时卡片也浮起来(:has,旧浏览器不认这一条,别的照常)。
   - 想让某一张一直浮着(比如当前选中的那张,或者用脚本控制),加 class="is-lifted"。
   - 鼠标停在卡片底边那几像素里时,卡片一浮起来鼠标就不在它上面了,会一浮一落;要完全避免,让外面一层不动、里面一层浮起来。
   - 卡片在 overflow: hidden 的框里、又贴着框的边时,浮起来的影子会被裁掉一截:给框留一点内边距。
   - 这个 class 会重写元素的 transition(transition 只能写一行,后写的盖掉先写的):元素原来就有过渡的(比如悬停变色),把原来的几项并进这一行。
   - 开启"减少动态"时:照样浮起来、影子变深,不做过渡。 */
.lift {
  --lift-distance: 4px;
  --lift-duration: 200ms;
  --lift-easing: cubic-bezier(0.33, 1, 0.68, 1);
  --lift-shadow: 0 12px 20px -8px rgb(0 0 0 / 0.15), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  transition: translate var(--lift-duration) var(--lift-easing), box-shadow var(--lift-duration) var(--lift-easing);
}
@media (hover: hover) {
  .lift:hover { translate: 0 calc(-1 * var(--lift-distance)); box-shadow: var(--lift-shadow); }
}
.lift:focus-visible, .lift.is-lifted { translate: 0 calc(-1 * var(--lift-distance)); box-shadow: var(--lift-shadow); }
.lift:has(:focus-visible) { translate: 0 calc(-1 * var(--lift-distance)); box-shadow: var(--lift-shadow); }
@media (prefers-reduced-motion: reduce) {
  .lift { transition: none; }
}
HTML
<!-- 悬停上浮:给卡片加上 class="lift"(卡片最好就是链接,键盘也能选中它),不需要脚本 -->
<div class="works">
  <a class="card lift" href="/works/1">
    <img src="cover-1.jpg" alt="">
    <h3>海报设计</h3>
  </a>
  <a class="card lift" href="/works/2">
    <img src="cover-2.jpg" alt="">
    <h3>记账小程序</h3>
  </a>
</div>

More in Hover & pointer

Browse all 86 effects →

Shown once per release · Always available in changelog