AI 很擅长把界面“做出来”:布局完整、颜色协调、组件齐全。但真正决定产品质感的,往往不是多画一个渐变、多放一段动效,而是组件在连续操作中是否稳定、反馈是否可信。

按钮就是最典型的试金石。它考验一次点击是否“按得下去”,而这一点并不显眼,却直接影响用户对产品的判断。

拟物按钮最容易做错的地方,是把它理解成“加阴影”。单纯的投影只会让按钮浮起来,不能解释它为什么像实体、为什么按下去有反馈。

一个可信的按钮,本质上是一块被光从正上方照亮的薄片。它的视觉由五层材料共同构成:

  1. 面板:用纵向渐变表达受光面,上缘略亮、下缘略暗。
  2. 边缘:一圈比底部更深的细边框,明确材料的厚度。
  3. 顶部高光:贴着上缘的一条内高光,模拟光源擦过表面。
  4. 底部暗边:贴着下缘的一条内阴影,暗示材料并非平面。
  5. 投影:一层贴地的接触阴影,加一层更柔的悬浮阴影。

这五层要在同一套材质 token 中定义,只按变体替换数值。否则 primary、secondary、tertiary 很容易逐渐长成三个互不相干的按钮,失去系统感。

颜色也不必复杂。中性灰足够表达层级:近黑面板承载主操作,白色面板适合次操作,浅灰面板再弱一级,ghost 和 text 则退到几乎只剩文字。没有品牌色干扰时,层级反而更清楚。

状态变化要改变“材料”,不只是颜色

悬停时把面板提亮一档,同时让悬浮阴影稍微变大,按钮会有轻微抬起的预期。按下时则要同时发生三件事:

  • 按钮下沉约 1px;
  • 渐变翻转,让上缘变暗,模拟受压后的受光变化;
  • 外投影收拢为贴近表面的接触阴影。

高光也要从“亮边”切换为内阴影。浅色按钮按压后,底部再保留一条极细的白线,会更像键帽压进纸面,而不是一块色块突然变色。

一个常被忽略的工程细节是:静止态和按压态的内阴影层数必须一致。缺少的层用透明阴影占位,浏览器才能在两种状态之间平滑插值;否则动画会在切换瞬间跳一下。

这里的时长应服从动作含义,而不是统一套一个“丝滑”数值:

  • transform:120ms。位移最直接,需要立刻响应。
  • box-shadow:140ms。阴影稍慢,重量变化才自然。
  • 颜色:160ms。材质变化可以比位移更柔和。

按钮尺寸也不应写死。以 14px 标签为基准定义尺寸单位 u,再把高度、内边距、圆角、图标和阴影偏移都按 u 缩放。这样 16px 标签的大号按钮不会出现“字变大了,但键帽比例还是小号”的割裂感。

先继承设计系统,再新增组件

如果项目已有组件库,正确做法不是再写一个“更好看”的 Button,而是沿用现有 Button 的 API、props 和无障碍行为,只替换其材质与变体 token。产品调用处不该因为视觉升级而被迫修改。

只有项目里完全没有 Button 时,才值得新建一个可复用的组件,并至少暴露 variant 与 size 两个维度。

按钮示例 Prompt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Define a tactile, skeuomorphic Button component with five variants, from
strongest to weakest: primary, secondary, tertiary, ghost, text.
If the project already has a component library or design system, do not
add a new component: restyle its existing Button through its own variant
and token system, and keep its API, props and accessibility as they are.
Otherwise create one reusable Button with `variant` and `size` props.

Style: calm and precise, like the Lumno browser extension and the Cloudflare
dashboard. Neutral grays only, no brand hues. Lit from straight above.
No glossy Web 2.0 shine, no glow, no large blur.

Variants:
1. primary - near-black slate face (#404859 -> #273042), white label
2. secondary - raised white key (#FFFFFF -> #F4F5F7), dark gray label
3. tertiary - soft gray key (#F3F4F6 -> #E7E9EC), dark gray label
4. ghost - no face at rest; faint gray fill on hover; a recessed well
when pressed
5. text - gray label with a thin underline and an arrow that nudges
right on hover

Every filled variant is the same five material layers; only the values
change, so define them once as tokens and let each variant set its own:
1. Face: 180deg linear gradient, top 6-8% lighter than bottom.
2. Edge: 1px solid border one step darker than the bottom of the face
(primary #12161F, secondary rgba(15,23,42,.14), tertiary rgba(15,23,42,.1)).
3. Top highlight: inset 0 1px 0 white (18% on slate, 85-100% on light
faces). Put every inset layer in the button's own box-shadow, before the
drop layers, never on a pseudo-element overlay: inset shadows on the
element follow the inner radius (outer radius minus border), so the
corners line up in every state.
4. Bottom shade: inset 0 -1px 0 black (22% on slate, 6% on light faces).
5. Drop shadow in two layers: a tight contact shadow 0 1px 2px plus a soft
lift 0 4px 10px -3px (18% and 28% on slate, about a third of that on
light faces).

States (hover, pressed/active, focus-visible, disabled):
- Hover: face one step lighter; the lift grows to 0 8px 16px -5px.
- Pressed: translateY(1px); flip the gradient (darker on top); the outer
shadow collapses to 0 1px 1px; the top highlight becomes an inner shadow,
inset 0 1px 2px black (40% on slate, 12-16% on light faces). Light faces
keep a 1px white line below, 0 1px 0 rgba(255,255,255,.9), like a key
pressed into paper.
- Give rest and pressed the same number of inset layers (pad with
inset 0 0 0 transparent) so the shadow animates instead of jumping.
- Focus-visible and disabled follow the library's existing conventions.
- Timing: 120ms for transform, 140ms for shadows, 160ms for colors.

Sizes: all values above are for the 14px label size: height 40px,
padding 0 18px, radius 10px, label weight 600, optional 16px leading icon.
On the slate face add a label text-shadow 0 -1px 0 rgba(0,0,0,.28).
Scale the material with the type, never keep it at fixed pixels: express
every length (height, padding, radius, border, icon, the 1px press offset,
and every shadow offset, blur and spread) as a multiple of a size unit
u = label size / 14. Provide two sizes: md (14px label, u = 1px) and
lg (16px label, u = 16/14 px, so height 45.7px, radius 11.4px, lift shadow
0 4.6px 11.4px -3.4px).

质感来自可解释的细节

按钮的材质分层解释了“它为什么像实体”,状态变化解释了“它为什么按得下去”。用户说不出具体参数,却能立刻感觉到产品是否可靠。

对 AI 生成界面而言,布局和配色已经越来越容易及格,真正拉开差距的,是这些能被逻辑解释、能被工程复用、也能被测试覆盖的交互约束。

站内搜索

没有找到内容!