@@ -9,8 +9,8 @@ element and it works quite similarily as well.
9
9
10
10
## Shadow Encapsulation: Scoped Styles
11
11
12
- Shadow DOM offers a boundary line between styles outside the tree, and styles inside the tree. Styles cannot cross
13
- this boundary unintentionally. This is different to regular CSS where a selector can effect every element on a page.
12
+ Shadow DOM offers a boundary line between styles outside the tree, and styles inside the tree. Styles cannot cross this
13
+ boundary unintentionally. This is different to regular CSS where a selector can effect every element on a page.
14
14
15
15
``` html
16
16
<style >
@@ -39,9 +39,9 @@ The `<p>` element within the shadow tree is not effected by the styles declared
39
39
40
40
Custom elements abide by the same rules of inheritance as other HTML elements. CSS properties whose default value is
41
41
` inherit ` will inherit from their parent element, for example ` font-size ` , ` font-family ` , and ` color ` . This ` inherit `
42
- property crosses the Shadow DOM boundary. [ CSS custom properties] [ ] default to ` inherit ` , so they'll cross Shadow DOM
43
- boundaries too. Top-level elements within a shadow tree inherit properties from the custom element itself (also known
44
- as the shadow host).
42
+ property crosses the Shadow DOM boundary. [ CSS custom properties] [ css-custom-properties ] default to ` inherit ` , so
43
+ they'll cross Shadow DOM boundaries too. Top-level elements within a shadow tree inherit properties from the custom
44
+ element itself (also known as the shadow host).
45
45
46
46
``` html
47
47
<style >
@@ -71,8 +71,8 @@ value will also be `deeppink`.
71
71
72
72
## Styling elements outside of a shadow tree
73
73
74
- In order to be portable, Web Components can provide default styles for the element itself (also known as the shadow host).
75
- They can also style slotted elements with some default styles.
74
+ In order to be portable, Web Components can provide default styles for the element itself (also known as the shadow
75
+ host). They can also style slotted elements with some default styles.
76
76
77
77
### Writing default styles for the shadow host with ` :host ` and ` :host() `
78
78
@@ -92,9 +92,9 @@ action:
92
92
</fancy-p >
93
93
```
94
94
95
- The ` :host() ` selector will select the shadow host if it matches a given selector. For example, it can be used to
96
- select for hosts that have a given attribute. While ` :host ` may apply to ` <fancy-p> ` component, ` :host([extra]) ` would
97
- apply only to ` <fancy-p extra> ` elements:
95
+ The ` :host() ` selector will select the shadow host if it matches a given selector. For example, it can be used to select
96
+ for hosts that have a given attribute. While ` :host ` may apply to ` <fancy-p> ` component, ` :host([extra]) ` would apply
97
+ only to ` <fancy-p extra> ` elements:
98
98
99
99
``` css
100
100
:host ([extra ]) {
@@ -104,8 +104,7 @@ apply only to `<fancy-p extra>` elements:
104
104
```
105
105
106
106
``` html
107
- <fancy-p >I not am extra</fancy-p >
108
- <fancy-p extra >I am extra</fancy-p >
107
+ <fancy-p >I not am extra</fancy-p > <fancy-p extra >I am extra</fancy-p >
109
108
```
110
109
111
110
#### Chaining selectors after ` :host `
@@ -127,7 +126,6 @@ it will select elements within the shadow tree.
127
126
</fancy-p >
128
127
```
129
128
130
-
131
129
### Writing default styles for slotted elements with ` ::slotted() `
132
130
133
131
The ` ::slotted() ` pseudo-element selector allows you to write default styles for slotted elements that match the given
@@ -260,14 +258,14 @@ The `<style>` tag is the most simple way to write styles for a Web Component. Ju
260
258
Using a ` <link rel="stylesheet"> ` element in the shadow tree will allow you to write styles in an external stylesheet.
261
259
262
260
``` html
263
- <link rel =" stylesheet" href =" /fancy-article-element.css" >
261
+ <link rel =" stylesheet" href =" /fancy-article-element.css" / >
264
262
```
265
263
266
264
If you do this, the stylesheet will be loaded after the script is loaded. This will likely cause a “flash of unstyled
267
265
content” (FOUC). To circumvent this, you can preload the stylesheet like this:
268
266
269
267
``` html
270
- <link rel =" preload" href =" /fancy-article-element.css" as =" style" >
268
+ <link rel =" preload" href =" /fancy-article-element.css" as =" style" / >
271
269
```
272
270
273
271
### Using Constructable Stylesheets
@@ -286,7 +284,7 @@ stylesheet.replaceSync(`
286
284
287
285
class FancyArticleElement extends HTMLElement {
288
286
connectedCallback () {
289
- this .attachShadow ({mode: ' open' }).adoptedStyleSheets = [stylesheet]
287
+ this .attachShadow ({ mode: " open" }).adoptedStyleSheets = [stylesheet]
290
288
}
291
289
}
292
290
```
@@ -298,13 +296,13 @@ assertion where the `type` is `css` and then you can add the imported stylesheet
298
296
the element’s shadow root.
299
297
300
298
``` js
301
- import stylesheet from ' ./fancy-article-element.css' assert { type : ' css ' }
299
+ import stylesheet from " ./fancy-article-element.css" assert { type : " css " }
302
300
303
301
class FancyArticleElement extends HTMLElement {
304
302
connectedCallback () {
305
- this .attachShadow ({mode: ' open' }).adoptedStyleSheets = [stylesheet]
303
+ this .attachShadow ({ mode: " open" }).adoptedStyleSheets = [stylesheet]
306
304
}
307
305
}
308
306
```
309
307
310
- [ CSS custom properties] : https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
308
+ [ css- custom- properties] : https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
0 commit comments