跳到正文
Simon Willison·· 2026-09-24AI 评分15

用可交互示例讲解 Shadow DOM 的 shadow roots

Shadow roots, explained with live examples

AI 导读

一篇用可交互示例讲解 shadow roots 的教程,演示样式封装、继承、slots、parts 以及 JavaScript 访问方式,展示 shadow root 如何创建带私有样式表和元素的隔离 DOM 树,并以受控方式与页面 DOM 交互。该示例由 Fable 5.1 Medium 根据提示词生成。

正文

Tool Shadow roots, explained with live examples — Learn about shadow DOM through interactive examples that demonstrate style encapsulation, inheritance, slots, parts, and JavaScript access. Explore how shadow roots create isolated DOM trees with private stylesheets and elements that interact with the page DOM in specific, controlled ways.

Prompt to Fable 5.1 Medium:

Build an artifact to explain shadow roots in CSS with interactive examples

来源:Simon Willison · simonwillison.net