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

embedded-or-inline-css

它能做什么

这项技能检查网页中直接写在 HTML 里的样式。适用于希望代码更清晰、更易维护的开发者。

适用场景

  • ✓当页面的 HTML 中散落着很多 style 属性的时候。
  • ✓当模板里有大段难以修改的样式代码的时候。
  • ✓当你希望浏览器能在多个页面之间复用样式的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/embedded-or-inline-css/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请帮我把页面里的内联样式移到单独的样式表中。”

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

工作原理

智能体会找出内联样式和内嵌样式,并建议把它们移到外部文件中。只保留首屏关键样式和动态值(例如 CSS 自定义属性)在页面内。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Avoid embedded and inline CSS

Inline CSS cannot be cached separately, increases HTML payload, breaks separation of concerns, and is harder to maintain in large codebases.

Quick Reference

  • Move inline styles to external CSS files or CSS-in-JS
  • Exception: critical CSS should be inlined for performance
  • Exception: dynamic values (CSS custom properties) can be inline
  • Inline CSS breaks caching and increases HTML size

Check

Verify that inline CSS and embedded styles are avoided except for valid use cases like critical CSS, dynamic styles, or performance optimization.

Fix

Move inline and embedded CSS to external stylesheets, keeping only critical above-the-fold CSS inline for performance optimization.

Explain

Explain why external CSS is preferred for maintainability, caching, and separation of concerns, with exceptions for critical CSS and dynamic styles.

Code Review

Review stylesheets, component styles, and responsive states related to Avoid embedded and inline CSS. 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/embedded-or-inline-css

常见问题

为什么外部样式表更好?

浏览器可以单独缓存它们,HTML 也会更小,更易维护。

什么时候可以使用内联 CSS?

这项技能允许保留首屏关键样式以及动态值,例如 CSS 自定义属性。

它是否涵盖框架?

在框架项目中,这项技能提到 CSS-in-JS 可作为一种选择。

详情

作者的原始描述

Use when reviewing stylesheets, component styles, and responsive behavior related to Avoid embedded and inline CSS. Check the rendered layout across breakpoints and interaction states before proposing a fix.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能