YL

TEXT EFFECT

移动线影Line Shadow Text

文字背后有两层描边副本向两侧错动一次后停住,留下「残影/回声」般的层次。Magic UI 的 line-shadow-text。

中英对照

中文
移动线影
英文
Line Shadow Text
别名
Shadow Offset Text、Echo Text、Ghost Text
一句话
文字背后有两层描边副本向两侧错动一次后停住,留下「残影/回声」般的层次。Magic UI 的 line-shadow-text。

效果预览

LINE SHADOW

适合用在哪

需要轻微动感的标题、音乐/潮流品牌、深色主题的文字强调。

不适合:24px 以下的字和多行标题:描边副本会糊进主文字,看起来像渲染错误;页面已经有其他持续运动的元素时也不要再加,左右错动的残影会和它们抢注意力。

和相近模式的区别

描边文字Outline / Stroke Text

描边文字本身就是镂空的,是一种静态的版式手段,靠轮廓的「轻」制造层次;移动线影的主角是一行实心文字,背后两层描边副本左右错动,像声音的回声,是一个短暂的动效,停下后残影静止地留在两侧作装饰。

容易踩的坑

  • 字号小于 24px 时副本描边糊进主文字,看起来像渲染错误。
  • 副本 data-t 与主文字不一致,切换语言后残影显示的是旧文案。
  • 左右往复位移持续运行,对前庭敏感用户应在减弱动效时关闭。

设计提示词 · Prompt

移动线影(Line Shadow Text):主文字正常填充显示。::after 用 content:attr(data-t) 复制同一段文字,颜色设为 transparent 并用 -webkit-text-stroke:1px 主色 45% 透明做描边副本。副本动画 3.2s cubic-bezier(.4,0,.2,1) 只播放一次:从 translateX(-5px) opacity:.2 到 translateX(7px) opacity:1,再落到 translateX(4px) opacity:.6 的静止残影;副本放在主文字后面(父元素 isolation:isolate,伪元素 z-index:-1),content 写成 attr(data-t) / "",避免读屏重复朗读。真实实现常叠两层副本,一层向左、一层向右,形成「回声」往两侧扩散。字号 24px 以上效果最明显。
Line Shadow Text: the main text displays with a normal fill. ::after duplicates the same text with content:attr(data-t), with color set to transparent and -webkit-text-stroke:1px in the primary color at 45% opacity as an outlined copy. The copy animates once over 3.2s cubic-bezier(.4,0,.2,1): from translateX(-5px) opacity:.2 to translateX(7px) opacity:1, settling on a static echo at translateX(4px) opacity:.6; place the copy behind the main text (isolation:isolate on the parent, z-index:-1 on the pseudo-element) and write its content as attr(data-t) / "" so screen readers do not read it twice. Real implementations often stack two copies, one moving left and one moving right, forming an "echo" that spreads to both sides. The effect is most visible at font sizes above 24px.

可复制 CSS

自包含的最小实现,粘贴到空白页面即可生效;类名可以按项目规范改名。

/* <h2 class="echo" data-t="LINE SHADOW">LINE SHADOW</h2>;data-t 必须与文字完全一致 */
.echo {
  position: relative;
  isolation: isolate;
  display: inline-block;
  margin: 0;
  color: #111827;
  font: 800 clamp(24px, 5vw, 56px)/1.1 system-ui, sans-serif;
  letter-spacing: .01em;
}
.echo::before,
.echo::after {
  content: attr(data-t);
  content: attr(data-t) / "";
  position: absolute;
  inset: 0;
  z-index: -1;
  color: transparent;
  -webkit-text-stroke: 1px rgba(79, 70, 229, .45);
  pointer-events: none;
  opacity: .6;
}
/* 两层副本各往一侧错动一次(3.2 秒),结束时停在 ±4px 的静止残影 */
.echo::before { transform: translateX(-4px); animation: echo-left 3.2s cubic-bezier(.4, 0, .2, 1) 1; }
.echo::after { transform: translateX(4px); animation: echo-right 3.2s cubic-bezier(.4, 0, .2, 1) 1; }
@keyframes echo-left {
  0% { transform: translateX(5px); opacity: .2; }
  50% { transform: translateX(-7px); opacity: 1; }
}
@keyframes echo-right {
  0% { transform: translateX(-5px); opacity: .2; }
  50% { transform: translateX(7px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .echo::before,
  .echo::after { animation: none; }
}
@media (forced-colors: active) {
  .echo::before,
  .echo::after { display: none; }
}

演示 HTML 结构

<div class="s d-center">
  <div class="tx-lshadow" data-t="LINE SHADOW">LINE SHADOW</div>
</div>

无障碍与性能

无障碍

  • 副本的 content 写成 attr(data-t) / "",替代文本为空,读屏只读一遍主文字。
  • 只错动一次,3.2 秒后停在静止的残影上,低于 SC 2.2.2 的 5 秒;左右位移最大 7px,prefers-reduced-motion: reduce 时直接显示静止残影,主文字始终清晰。
  • 强制颜色模式下隐藏两层副本,避免描边被换成系统颜色后和主文字叠成一团。

性能

  • 只动画两个伪元素的 transform 和 opacity;描边本身是静态的,不参与动画。

常见问题

移动线影的英文是什么?

移动线影的英文是 Line Shadow Text。常见英文别名还包括 Shadow Offset Text、Echo Text、Ghost Text。

Line Shadow Text 的中文是什么?

Line Shadow Text 的中文是「移动线影」。文字背后有两层描边副本向两侧错动一次后停住,留下「残影/回声」般的层次。Magic UI 的 line-shadow-text。

残影副本为什么要放在主文字后面?

副本在上方时,描边会压在实心笔画上,看起来像渲染错误。本条给标题加 isolation: isolate,让它自己成为层叠上下文,副本再用 z-index: -1 退到标题内部的最底层;不加 isolation 时,z-index: -1 的伪元素可能退到父级甚至页面背景后面,整个看不见。

副本用伪元素还是用两个 span 做?

伪元素配 attr(data-t) 少写 HTML,但要保证 data-t 和文字同步,并用 content 的替代文本语法屏蔽读屏。两个 aria-hidden="true" 的 span 可以放任意内容(换行、带样式的词),由 JS 或模板渲染时也更容易和主文字保持一致;文案经常变化或要支持多语言时选 span。

常见搭配

同一页面里经常和「移动线影」一起出现的模式,可以收藏后用「组合收藏为整页提示词」一起交给 AI。

标签