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

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

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

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能