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

css-containment

它能做什么

这项技能展示如何使用 contain 属性和 content-visibility,告诉浏览器某些组件是自包含的。适合页面中有大量组件、而感觉运行缓慢的开发者。

适用场景

  • ✓当包含许多独立组件的页面在更新时感觉迟缓时。
  • ✓当长列表渲染了屏幕之外的内容时。
  • ✓当一个小组件没有溢出内容,也不需要影响页面其他部分时。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“我的长商品列表滚动时有些卡顿。请添加 containment,让屏幕之外的项目少渲染一些。”

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

工作原理

智能体会为自包含的组件添加 contain 值,并为重复出现的屏幕外列表项添加 content-visibility: auto,同时确认它们不会溢出或影响相邻元素。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Use CSS containment to limit repaint scope

By default, a CSS change anywhere on the page can potentially affect any other element's layout. CSS containment declares that certain elements are isolated — changes inside them don't affect the outside world. This lets browsers skip large portions of the rendering pipeline for unchanged content, which is especially valuable for pages with many independent components.

Quick Reference

  • contain: layout style paint tells the browser a component is visually self-contained
  • content-visibility: auto skips rendering off-screen content entirely
  • Containment limits how far layout recalculations need to propagate
  • Use contain: strict for widgets with no overflow that shouldn't affect the page

Check

Identify components in this CSS that are visually self-contained (no overflow, no interaction with elements outside) and could benefit from CSS containment.

Fix

Add appropriate contain values to self-contained components. Add content-visibility: auto to repeated off-screen list items.

Explain

Explain CSS containment values, how they limit rendering scope, and when content-visibility: auto provides the biggest benefit.

Code Review

Review stylesheets, component styles, and responsive states related to Use CSS containment to limit repaint scope. 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/css-containment

常见问题

contain 有什么作用?

这项技能说明,它告诉浏览器某个组件在视觉上是自包含的,因此布局计算可以局限在其内部。

content-visibility: auto 有什么作用?

这项技能说明,它会跳过渲染屏幕之外的内容。

什么时候使用 strict 形式的 contain?

用于没有溢出内容、并且不应影响页面其他部分的小组件。

详情

作者的原始描述

Use when reviewing stylesheets, component styles, and responsive behavior related to Use CSS containment to limit repaint scope. Check the rendered layout across breakpoints and interaction states before proposing a fix.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能