better-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDetails that make interfaces feel better
让界面更舒适的细节
Great interfaces rarely come from a single thing. It's usually a collection of small details that compound into a great experience. Apply these principles when building or reviewing UI code.
Typography (text wrapping, font smoothing, tabular numbers, spacing) is covered by the skill — use that for anything text-related.
better-typography优秀的界面很少源于单一设计,通常是众多微小细节共同作用,才形成极佳的体验。在构建或评审UI代码时,请遵循以下原则。
排版相关内容(文本换行、字体平滑、表格数字、间距)由技能覆盖——任何文本相关工作都请使用该技能。
better-typographyQuick Reference
快速参考
| Category | When to Use |
|---|---|
| Surfaces | Border radius, optical alignment, shadows, image outlines, hit areas |
| Animations | Interruptible animations, enter/exit transitions, icon animations, scale on press |
| Performance | Transition specificity, |
| 分类 | 使用场景 |
|---|---|
| Surfaces | border radius、光学对齐、阴影、image outlines、点击区域 |
| Animations | 可中断动画、进入/退出过渡、图标动画、按压缩放 |
| Performance | 过渡属性指定、 |
Core Principles
核心原则
1. Concentric Border Radius
1. 同心圆角
Outer radius = inner radius + padding. Mismatched radii on nested elements is the most common thing that makes interfaces feel off.
外圆角半径 = 内圆角半径 + 内边距。嵌套元素圆角不匹配是导致界面违和的最常见问题。
2. Optical Over Geometric Alignment
2. 光学对齐优先于几何对齐
When geometric centering looks off, align optically. Buttons with icons, play triangles, and asymmetric icons all need manual adjustment.
当几何居中看起来不协调时,采用光学对齐。带图标的按钮、播放三角形和不对称图标都需要手动调整。
3. Shadows Over Borders
3. 用阴影替代边框
Layer multiple transparent values for natural depth. Shadows adapt to any background; solid borders don't.
box-shadow叠加多层半透明值以营造自然的层次感。阴影能适配任何背景,而实色边框则无法做到。
box-shadow4. Interruptible Animations
4. 可中断动画
Use CSS transitions for interactive state changes — they can be interrupted mid-animation. Reserve keyframes for staged sequences that run once.
使用CSS过渡实现交互状态变化——它们可以在动画中途被中断。关键帧动画仅用于一次性的阶段性序列。
5. Split and Stagger Enter Animations
5. 拆分并交错进入动画
Don't animate a single container. Break content into semantic chunks and stagger each with ~100ms delay.
不要对单个容器应用动画。将内容拆分为语义化区块,并为每个区块设置约100ms的延迟交错播放。
6. Subtle Exit Animations
6. 柔和的退出动画
Use a small fixed instead of full height. Exits should be softer than enters.
translateY使用小幅度固定而非全高度位移。退出动画应比进入动画更柔和。
translateY7. Contextual Icon Animations
7. 上下文图标动画
Animate icons with , , and instead of toggling visibility. Use exactly these values: scale from to , opacity from to , blur from to . If the project has or in , use — bounce must always be . If no motion library is installed, keep both icons in the DOM (one absolute-positioned) and cross-fade with CSS transitions using — this gives both enter and exit animations without any dependency.
opacityscaleblur0.251014px0pxmotionframer-motionpackage.jsontransition: { type: "spring", duration: 0.3, bounce: 0 }0cubic-bezier(0.2, 0, 0, 1)使用、和为图标添加动画,而非直接切换可见性。请严格使用以下值:scale从到,opacity从到,blur从到。如果项目的中包含或,请使用——bounce值必须始终为。如果未安装动画库,请将两个图标都保留在DOM中(其中一个设为绝对定位),并使用CSS过渡通过实现交叉淡入淡出——这样无需依赖任何库即可实现进入和退出动画。
opacityscaleblur0.251014px0pxpackage.jsonmotionframer-motiontransition: { type: "spring", duration: 0.3, bounce: 0 }0cubic-bezier(0.2, 0, 0, 1)8. Image Outlines
8. 图片轮廓
Add a subtle outline with low opacity to images for consistent depth. The color must be pure black in light mode () and pure white in dark mode () — never a near-black like slate, zinc, or any tinted neutral. A tinted outline picks up the surface color underneath it and reads as dirt on the image edge.
1pxoklch(0 0 0 / 0.1)oklch(1 0 0 / 0.1)为图片添加1px低透明度的细微轮廓,以保持一致的层次感。亮色模式下颜色必须为纯黑色(),暗色模式下必须为纯白色()——绝不能使用深灰、锌灰或任何带色调的中性色。带色调的轮廓会沾染下方的表面颜色,看起来像图片边缘的污渍。
oklch(0 0 0 / 0.1)oklch(1 0 0 / 0.1)9. Scale on Press
9. 按压缩放
A subtle on click gives buttons tactile feedback. Always use . Never use a value smaller than — anything below feels exaggerated. Add a prop to disable it when motion would be distracting.
scale(0.96)0.960.95static点击时应用细微的为按钮提供触觉反馈。请始终使用。绝不要使用小于的值——低于该值会显得过于夸张。如果动画会分散注意力,请添加属性禁用该效果。
scale(0.96)0.960.95static10. Skip Animation on Page Load
10. 页面加载时跳过动画
Use on to prevent enter animations on first render. Verify it doesn't break intentional entrance animations.
initial={false}AnimatePresence在上使用以防止首次渲染时播放进入动画。请确认此设置不会破坏有意设置的入场动画。
AnimatePresenceinitial={false}11. Never Use transition: all
transition: all11. 切勿使用transition: all
transition: allAlways specify exact properties: . Tailwind's covers .
transition-property: scale, opacitytransition-transformtransform, translate, scale, rotate始终指定精确的属性:。Tailwind的涵盖。
transition-property: scale, opacitytransition-transformtransform, translate, scale, rotate12. Use will-change
Sparingly
will-change12. 谨慎使用will-change
will-changeOnly for , , — properties the GPU can composite. Never use . Only add when you notice first-frame stutter.
transformopacityfilterwill-change: all仅用于、、——这些是GPU可合成的属性。绝不要使用。仅当你注意到第一帧卡顿才添加该属性。
transformopacityfilterwill-change: all13. Minimum Hit Area
13. 最小点击区域
Interactive elements need a 44×44px hit area for touch or mobile contexts. In desktop interfaces, use at least 40×40px. Extend with a pseudo-element if the visible element is smaller. Never let hit areas of two elements overlap.
交互元素在触摸或移动场景下需要44×44px的点击区域。在桌面界面中,至少使用40×40px。如果可见元素较小,可使用伪元素扩展点击区域。绝不要让两个元素的点击区域重叠。
Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| Same border radius on parent and child | Calculate |
| Icons look off-center | Adjust optically with padding or fix SVG directly |
| Hard borders between sections | Use layered |
| Jarring enter/exit animations | Split, stagger, and keep exits subtle |
| Animation plays on page load | Add |
| Specify exact properties |
| First-frame animation stutter | Add |
| Tiny hit areas on small controls | Extend with a pseudo-element to 44×44px for touch/mobile, or at least 40×40px in desktop UI |
| 错误 | 修复方案 |
|---|---|
| 父元素和子元素使用相同的圆角半径 | 计算 |
| 图标看起来偏移中心 | 使用内边距进行光学调整,或直接修改SVG |
| 区块间使用实色边框 | 使用多层半透明 |
| 进入/退出动画过于突兀 | 拆分、交错动画,并让退出动画更柔和 |
| 页面加载时播放动画 | 为 |
元素上使用 | 指定精确的过渡属性 |
| 动画第一帧卡顿 | 谨慎添加 |
| 小型控件的点击区域过小 | 使用伪元素扩展至触摸/移动场景的44×44px,或桌面UI的至少40×40px |
Review Output Format
评审输出格式
Always present changes as a markdown table with Before and After columns. Include every change you made — not just a subset. Never list findings as separate "Before:" / "After:" lines outside of a table. Group changes by principle using a heading above each table, and keep each row focused on a single diff so the reader can scan the whole list quickly.
请始终以包含Before和After列的Markdown表格呈现修改内容。列出所有修改——不要只列出部分内容。绝不要在表格外以单独的「Before:」/「After:」行列出修改。按原则分组,在每个表格上方添加标题,每行聚焦于单个差异,以便读者快速浏览整个列表。
Example
示例
Concentric border radius
同心圆角
| Before | After |
|---|---|
| |
| Outer |
| Before | After |
|---|---|
卡片使用 | 卡片使用 |
两个嵌套元素都使用 | 外部元素使用 |
Scale on press
按压缩放
| Before | After |
|---|---|
| Added |
| Raised to |
Rows should cite the specific file and the specific property that changed when it isn't obvious from the snippet. If a principle was reviewed but nothing needed to change, omit that table entirely — empty tables add noise.
| Before | After |
|---|---|
| 添加 |
按压时使用 | 调整为 |
如果修改内容不明显,每行应注明具体的文件和修改的属性。如果某条原则已评审但无需修改,请完全省略该表格——空表格会增加冗余信息。
Review Checklist
评审检查清单
- Nested rounded elements use concentric border radius
- Icons are optically centered, not just geometrically
- Shadows used instead of borders where appropriate
- Enter animations are split and staggered
- Exit animations are subtle
- Images have subtle outlines
- Buttons use scale on press where appropriate
- AnimatePresence uses for default-state elements
initial={false} - No — only specific properties
transition: all - only on transform/opacity/filter, never
will-changeall - Interactive elements have 44×44px hit areas for touch/mobile, or at least 40×40px in desktop UI
- 嵌套圆角元素使用同心圆角
- 图标采用光学对齐,而非仅几何对齐
- 适当使用阴影替代边框
- 进入动画已拆分并交错播放
- 退出动画柔和自然
- 图片添加了细微轮廓
- 按钮已按需添加按压缩放效果
- 默认状态元素的使用了
AnimatePresenceinitial={false} - 未使用——仅指定了精确属性
transition: all - 仅用于transform/opacity/filter,从未使用
will-changeall - 交互元素在触摸/移动场景下有44×44px的点击区域,或在桌面UI中至少有40×40px
Reference Files
参考文件
- surfaces.md — Border radius, optical alignment, shadows, image outlines
- animations.md — Interruptible animations, enter/exit transitions, icon animations, scale on press
- performance.md — Transition specificity, usage
will-change
- surfaces.md —— border radius、光学对齐、阴影、image outlines
- animations.md —— 可中断动画、进入/退出过渡、图标动画、按压缩放
- performance.md —— 过渡属性指定、使用
will-change