YL

BUTTON

流光边框按钮Border Beam Button

一圈亮光只沿着按钮描边转,按钮脸上保持安静。

中英对照

中文
流光边框按钮
英文
Border Beam Button
别名
跑马灯边框、锥形渐变按钮、流光按钮
一句话
一圈亮光只沿着按钮描边转,按钮脸上保持安静。

效果预览

适合用在哪

定价页的推荐档、深色页面上需要被看见、但又不想整颗发光的主 CTA。

不适合:浅色、留白多的页面:流光的青色和品红在白底上对比弱、像描边闪烁的故障;需要用户长时间停留阅读的区域(文章正文旁、表单旁)也不适合放一个反复转圈、持续吸引注意力的按钮。

和相近模式的区别

流光边框卡片Conic Border Card / Animated Gradient Border

原理相同(@property 注册角度 + conic-gradient 旋转),也都是加载时转一圈就停、悬停或聚焦时再转一圈;区别在用量:流光边框卡片是整圈多色渐变(色 A → B → C → A)铺满卡片四周,转一圈约 5 秒;流光边框按钮只让约 30% 的弧发亮、其余透明,3 秒转一圈,像一束光沿着按钮边跑过。

渐变发光按钮Gradient Glow Button

想让推荐按钮在静止状态下(包括减弱动效、截图)也足够显眼时,换发光按钮:渐变实心加外扩光晕,不依赖运动;流光边框停下后只剩一段细亮弧,存在感弱很多。两者不要叠在同一颗按钮上。

容易踩的坑

  • 锥形渐变铺满整圈且颜色很满,看起来像彩虹描边,不再是「一束光在走」。
  • 光环用了 z-index:-1 但按钮没有 isolation,光被卡片背景吃掉。
  • 和发光按钮叠在同一个 CTA 上,脸上有光晕、边上又有光,主次一起糊掉。

设计提示词 · Prompt

流光边框按钮(Border Beam Button):外圈 1.5px,用 conic-gradient 只让约 30% 的弧发亮(青→品红),其余透明。用 @property 注册一个角度,让渐变的 from 在 2.5-3.5s 内转一圈。内层是实心深色圆角面,光只走在描边上,不要铺满按钮脸(那是扫光)也不要在按钮外再糊一圈(那是发光)。按钮设 isolation:isolate,避免负 z-index 的光环掉到卡片背景后面。一屏只用一颗。prefers-reduced-motion 时停在一帧静态渐变边。
Border Beam Button: a 1.5px outer ring using a conic-gradient where only about 30% of the arc is bright (cyan to magenta) and the rest is transparent. Register an angle with @property and rotate the gradient's from angle over 2.5-3.5s. The inner face is a solid dark rounded fill — the light travels the border only. Don't flood the button face (that is a shine sweep) and don't blur a halo outside the button (that is a glow). Set isolation:isolate on the button so a negative z-index ring doesn't fall behind the card background. Use only one per screen. Under prefers-reduced-motion, freeze on a single static gradient frame.

可复制 CSS

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

/* <button class="beam-btn" type="button"><span>立即升级</span></button> */
@property --beam-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}
.beam-btn {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  padding: 1.5px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
}
.beam-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: conic-gradient(from var(--beam-angle, 0deg), transparent 0 72%, #22d3ee 84%, #c026d3 94%, transparent);
  animation: beam-spin 3s linear 1;
}
.beam-btn > span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 45px;
  padding: 0 24px;
  border-radius: 10.5px;
  background: #111827;
  color: #fff;
  font: 600 15px/1 system-ui, sans-serif;
}
.beam-btn:focus-visible { outline: 2px solid #22d3ee; outline-offset: 3px; }
/* 保留已播完的 beam-spin、再追加一圈 replay:移开时 replay 被移除,beam-spin 不会重新开始 */
.beam-btn:hover::before, .beam-btn:focus-visible::before { animation: beam-spin 3s linear 1, beam-spin-replay 3s linear 1; }
@keyframes beam-spin {
  to { --beam-angle: 360deg; }
}
@keyframes beam-spin-replay {
  to { --beam-angle: 360deg; }
}
@media (prefers-reduced-motion: reduce) {
  .beam-btn::before, .beam-btn:hover::before, .beam-btn:focus-visible::before { animation: none; --beam-angle: 135deg; }
}

演示 HTML 结构

<div class="s" style="display:flex;justify-content:center;padding:16px 0">
  <button class="d-beambtn" type="button"><span>立即升级</span></button>
</div>

无障碍与性能

无障碍

  • 流光是纯装饰,按钮文字放在内层 span 里,可访问名称不受影响,不需要额外 aria 属性。
  • prefers-reduced-motion: reduce 时停在一段静止的亮弧上,保留「这是推荐操作」的视觉提示。
  • 按 WCAG SC 2.2.2,自动开始、持续超过 5 秒的移动内容必须能暂停、停止或隐藏。这里只转一圈(3 秒)就停,悬停或聚焦时再转一圈;如果产品坚持无限循环,必须另外提供暂停控件,不要只依赖 prefers-reduced-motion。

性能

  • 改变 conic-gradient 的角度需要每帧重绘这一层,不能像 transform 那样只走合成;按钮面积小,一颗的开销可以忽略,但同屏不要放多颗。
  • 只转一圈、悬停或聚焦时再转一圈,不会常驻占用动画帧;如果做成无限循环,除了提供暂停控件,还要在按钮滚出视口时用 IntersectionObserver 加 animation-play-state: paused,回到视口再恢复。

常见问题

流光边框按钮的英文是什么?

流光边框按钮的英文是 Border Beam Button。

Border Beam Button 的中文是什么?

Border Beam Button 的中文是「流光边框按钮」。常见中文别名还包括 跑马灯边框、锥形渐变按钮、流光按钮。一圈亮光只沿着按钮描边转,按钮脸上保持安静。

@property 的兼容性怎么样?不支持会怎样?

Chrome、Edge 85 起,Safari 16.4 起,Firefox 128 起支持。不支持时 --beam-angle 只是普通自定义属性,无法在关键帧里平滑插值,本条写了 var(--beam-angle, 0deg) 兜底,所以会停在一段静止的亮弧上,按钮照常可用。

流光边框能不能不用 @property 实现?

可以:在按钮里放一个比按钮对角线还大的方形伪元素,铺上 conic-gradient,用 transform: rotate() 旋转,按钮 overflow: hidden 裁掉多余部分,内层实心面盖住中间。transform 动画兼容性更好、可以走合成;代价是要多算一个足够大的尺寸,且按钮必须裁剪溢出。

用 border-image 做渐变边框可以吗?

不适合圆角按钮。border-image 不会被 border-radius 裁成圆角,四个角始终是直角;所以圆角的渐变边框通常用「外层渐变背景 + 内边距 1.5px + 内层实心面」或伪元素来做。

常见搭配

同一页面里经常和「流光边框按钮」一起出现的模式,可以收藏后用「组合收藏为整页提示词」一起交给 AI。

标签