flexbox-patterns
它能做什么
这项技能检查 CSS flexbox 代码中会破坏布局的常见错误。适用于使用 flex 构建页面布局的开发者。
适用场景
- ✓当文字在 flex 行中溢出或被裁切的时候。
- ✓当 flex 项目之间的间距不均匀或难以控制的时候。
- ✓当项目以你未预期的方式收缩或伸展的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/flexbox-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请检查我的 flexbox CSS 中是否有会破坏布局的错误。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会查找导致收缩或溢出问题的 flex 设置,以及在 gap 更合适的地方使用的 margin。它会建议修正后的数值,并在需要时修复 min-width。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Apply Flexbox best practices
Flexbox is one of the most used CSS features, but its unintuitive default values (flex-shrink:1, min-width:auto) cause layout bugs that are hard to diagnose. Understanding the flex shorthand and the min-width:0 fix prevents the most common Flexbox breakage scenarios.
Quick Reference
- Flexbox is for one-dimensional layouts (a row OR a column)
- Use flex: 1 1 0 (shorthand: flex:1) for equal-width items that fill space
- Add min-width: 0 to flex children when text overflow truncation doesn't work
- Use gap instead of margin for spacing between flex items
Check
Review this CSS for common Flexbox mistakes: missing min-width:0 on text-containing flex children, using margin instead of gap for spacing, and improper flex shorthand usage.
Fix
Fix the Flexbox layout issues: add min-width:0 where needed, replace inter-item margins with gap, and correct flex shorthand values.
Explain
Explain how flex-grow, flex-shrink, and flex-basis work, what the flex shorthand means, and why min-width:0 fixes text overflow in flex layouts.
Code Review
Review stylesheets, component styles, and responsive states related to Apply Flexbox best practices. 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/flexbox-patterns
常见问题
为什么 flex 布局中的文字会溢出?
flex 子元素有默认的最小宽度,可能导致文字无法收缩。这项技能建议将 min-width 设为 0 来修复。
应该使用 gap 还是 margin?
这项技能推荐使用 gap 来设置 flex 项目之间的间距。
flex: 1 是什么意思?
这项技能解释它是一个简写,表示项目平均分配可用空间。
详情
作者的原始描述
Use when reviewing stylesheets, component styles, and responsive behavior related to Apply Flexbox best practices. Check the rendered layout across breakpoints and interaction states before proposing a fix.
热度
- GitHub 星标
- 75k
- 排名
- #2848
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。