跳到正文
Skillpedia
网站与界面(前端)75k · #2999

responsive-units

它能做什么

这个技能检查样式表中固定的像素字号和宽度,并将其转换为相对单位。它面向希望布局尊重用户设置、并适应多种屏幕尺寸的前端开发者。

适用场景

  • ✓你请智能体让样式表更适应不同屏幕的时候。
  • ✓访客调大了默认字体,却发现你网站上的文字没有变大的时候。
  • ✓你希望让元素根据可用空间自适应,从而减少断点的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/responsive-units/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/responsive-units/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2999
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能