responsive-units
它能做什么
这个技能检查样式表中固定的像素字号和宽度,并将其转换为相对单位。它面向希望布局尊重用户设置、并适应多种屏幕尺寸的前端开发者。
适用场景
- ✓你请智能体让样式表更适应不同屏幕的时候。
- ✓访客调大了默认字体,却发现你网站上的文字没有变大的时候。
- ✓你希望让元素根据可用空间自适应,从而减少断点的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/responsive-units/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“一些访客调大了字体,但我的文字没有变化。请帮我把 CSS 中固定的像素尺寸转换为相对单位吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出应该自适应的、以像素为单位的字号、宽度和间距值。它会把字号转换为 rem,把宽度转换为百分比或 flex 和 grid 布局,并建议使用 clamp 让标题平滑缩放。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use relative units for responsive layouts
Fixed pixel values override user browser preferences, making your site inaccessible to users who increase their default font size (a common accommodation for low vision). Relative units also reduce the number of breakpoints needed — elements naturally adapt to available space rather than requiring explicit overrides at every viewport width.
Quick Reference
- Use rem for font sizes — it respects user browser font size preferences
- Use % or flex/grid for widths — they adapt to the parent container
- Use em for component-relative spacing (padding, border-radius)
- Use clamp() for fluid typography that scales smoothly between breakpoints
Check
Find all px-based font-size, width, and padding values in this CSS file that should use relative units instead.
Fix
Convert fixed px font sizes to rem equivalents and replace fixed widths with percentage or relative alternatives.
Explain
Explain the difference between rem, em, %, vw, and vh, and when to use each one.
Code Review
Review stylesheets, component styles, and responsive states related to Use relative units for responsive layouts. Flag exact selectors, declarations, or breakpoints that violate the rule in the rendered UI.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/css/responsive-units
常见问题
为什么 rem 有帮助?
它以用户的默认字体大小为基准,因此用户在浏览器中更改设置时,文字也会随之变大。
什么时候应该使用 em?
这个技能建议用于应随组件一起缩放的间距和圆角。
clamp 有什么作用?
它能让文字在屏幕变化时,在最小和最大尺寸之间平滑地缩放。
详情
作者的原始描述
Use when reviewing stylesheets, component styles, and responsive behavior related to Use relative units for responsive layouts. Check the rendered layout across breakpoints and interaction states before proposing a fix.
热度
- GitHub 星标
- 75k
- 排名
- #2999
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。