diff --git a/ShadowDOM/explainer.md b/ShadowDOM/explainer.md index 8f1d9f8c..3bf439db 100644 --- a/ShadowDOM/explainer.md +++ b/ShadowDOM/explainer.md @@ -83,7 +83,118 @@ This document explores several proposals that would allow developers to apply st ## Non-goals Some developers have expressed interest in CSS selectors crossing through the Shadow DOM, as discussed in [issue 909](https://github.com/WICG/webcomponents/issues/909#issuecomment-1977487651). While this scenario is related to sharing styles with Shadow DOM elements, it is solving a different problem and should be addressed separately. -## Use case +## Use case +### Pages with sub-sections +In some web pages with sub-sections that feature unique CSS styles distinct from the rest of the page, a combination of inherited global styles and highly specific CSS is used, which applies only to those sub-sections. The regular HTML structure often forces the browser to process CSS before rendering the first visual elements. When there is a significant number of styles, it can negatively impact page performance. Due to the limitations in style sharing with Declarative Shadow DOM, web authors cannot selectively share styles between the parent document and shadow roots. Here is an example of a web page with global, shared and unique styles: + +![image](images/webpagewithsubsection.png) + +In this example, CSS variables such as `--font-family` and `--text-color` were added to the global styles, which are used in the main document and within the shadow DOM. + +```html + + + + + + +

Web Page with Global, Shared, and Unique Styles

+ + +
+

Section 1

+

This section uses the global styles defined in the document.

+
+ + +``` + + Meanwhile, the shadow DOM section uses shared styles defined in the parent document, but also has its unique styles +```js + // Creating a shadow DOM host + const shadowHost = document.createElement('div'); + document.body.appendChild(shadowHost); + + // Attaching shadow root + const shadowRoot = shadowHost.attachShadow({ mode: 'open' }); + + // Defining shadow DOM content with shared and unique styles + shadowRoot.innerHTML = ` +``` + +```html + + + +
+

Shadow DOM with Shared and Unique Styles

+

This sub-section shares global styles using CSS variables but also applies its own unique styles inside the shadow DOM.

+
+ `; + +``` + ### Media site control widgets Sharing styles between the parent document and shadow root is also fairly common for media site control widgets such as play/pause buttons, volume sliders, and progress bars, to share styles diff --git a/ShadowDOM/images/bing serp.png b/ShadowDOM/images/bing serp.png deleted file mode 100644 index 795e43a6..00000000 Binary files a/ShadowDOM/images/bing serp.png and /dev/null differ diff --git a/ShadowDOM/images/webpagewithsubsection.png b/ShadowDOM/images/webpagewithsubsection.png new file mode 100644 index 00000000..4994b1ab Binary files /dev/null and b/ShadowDOM/images/webpagewithsubsection.png differ