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

css-expert

它能做什么

这个技能为现代 CSS 提供指导,包括 flexbox、grid、自定义属性和容器查询,用于制作自适应布局。适合构建网页的前端开发者和设计师。

适用场景

  • ✓当你需要一个从手机到桌面都能自适应的页面布局时。
  • ✓当你要为某个区块在 flexbox 和 grid 之间做选择时。
  • ✓当你希望把颜色和间距保存为设计令牌以便重复使用时。

技能链接

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/css-expert/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请把我的产品卡片排成自适应网格,桌面端显示三列,手机端显示一列。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能推荐用 flexbox 处理单行或单列,用 grid 处理二维布局,用自定义属性实现主题,并使用移动优先的媒体查询。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

CSS Expert

A front-end layout specialist with deep command of modern CSS, from flexbox and grid to container queries and cascade layers. This skill provides precise, standards-compliant guidance for building responsive, accessible, and maintainable user interfaces using the latest CSS specifications and best practices.

Key Principles

  • Use flexbox for one-dimensional layouts (rows or columns) and CSS Grid for two-dimensional layouts (rows and columns simultaneously)
  • Embrace custom properties (CSS variables) for theming, spacing scales, and any value that repeats or needs runtime adjustment
  • Design mobile-first with min-width media queries, layering complexity as viewport size increases
  • Prefer logical properties (inline-start, block-end) over physical ones (left, bottom) for internationalization-ready layouts
  • Leverage the cascade intentionally with @layer declarations to control specificity without resorting to !important

Techniques

  • Use flexbox justify-content and align-items for main-axis and cross-axis alignment; flex-wrap with gap for fluid card layouts
  • Define CSS Grid layouts with grid-template-areas for named regions, and auto-fit/auto-fill with minmax() for responsive grids without media queries
  • Create design tokens as custom properties on :root (--color-primary, --space-md) and override them in scoped selectors or media queries
  • Use @container queries to style components based on their parent container size rather than the viewport
  • Build animations with @keyframes and animation shorthand; prefer transform and opacity for GPU-accelerated, jank-free motion
  • Apply transitions on interactive states (hover, focus-visible) with appropriate duration (150-300ms) and easing functions
  • Use the :has() selector for parent-aware styling, :is()/:where() for grouping selectors with controlled specificity

Common Patterns

  • Holy Grail Layout: CSS Grid with grid-template-rows (auto 1fr auto) and grid-template-columns (sidebar content sidebar) for header/footer/sidebar page structures
  • Fluid Typography: clamp(1rem, 2.5vw, 2rem) for font sizes that scale smoothly between minimum and maximum values without breakpoints
  • Aspect Ratio Boxes: Use the aspect-ratio property directly instead of the legacy padding-bottom hack for responsive media containers
  • Dark Mode Toggle: Define color tokens as custom properties, swap them inside a prefers-color-scheme media query or a data-theme attribute selector

Pitfalls to Avoid

  • Do not use fixed pixel widths for layout containers; prefer percentage, fr units, or min/max constraints for fluid responsiveness
  • Do not stack z-index values arbitrarily; establish a z-index scale in custom properties and document each layer's purpose
  • Do not rely on vendor prefixes without checking current browser support; tools like autoprefixer handle this systematically
  • Do not nest selectors excessively in preprocessors, as the generated CSS becomes highly specific and difficult to maintain or override
常见问题

什么时候应该用 grid 而不是 flexbox?

当布局需要同时处理行和列时用 grid;只排一行项目时用 flexbox。

什么是设计令牌?

它是有名字的值,例如主色或间距大小,以 CSS 自定义属性的形式保存,并在整个页面中重复使用。

它能避免使用 !important 覆盖吗?

能。该技能建议用级联层来控制优先级,而不是依赖 !important。

详情

作者的原始描述

CSS expert for flexbox, grid, animations, responsive design, and modern layout techniques

repo: RightNow-AI/openfang

热度

GitHub 星标
18k
排名
#10671
许可证
Apache-2.0
更新时间
2026/7/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能