Skip to content

Commit 769f3e9

Browse files
committed
Format styling post
1 parent 053f3a8 commit 769f3e9

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

learn/components/styling.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ element and it works quite similarily as well.
99

1010
## Shadow Encapsulation: Scoped Styles
1111

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.
1414

1515
```html
1616
<style>
@@ -39,9 +39,9 @@ The `<p>` element within the shadow tree is not effected by the styles declared
3939

4040
Custom elements abide by the same rules of inheritance as other HTML elements. CSS properties whose default value is
4141
`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).
4545

4646
```html
4747
<style>
@@ -71,8 +71,8 @@ value will also be `deeppink`.
7171

7272
## Styling elements outside of a shadow tree
7373

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.
7676

7777
### Writing default styles for the shadow host with `:host` and `:host()`
7878

@@ -92,9 +92,9 @@ action:
9292
</fancy-p>
9393
```
9494

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:
9898

9999
```css
100100
:host([extra]) {
@@ -104,8 +104,7 @@ apply only to `<fancy-p extra>` elements:
104104
```
105105

106106
```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>
109108
```
110109

111110
#### Chaining selectors after `:host`
@@ -127,7 +126,6 @@ it will select elements within the shadow tree.
127126
</fancy-p>
128127
```
129128

130-
131129
### Writing default styles for slotted elements with `::slotted()`
132130

133131
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
260258
Using a `<link rel="stylesheet">` element in the shadow tree will allow you to write styles in an external stylesheet.
261259

262260
```html
263-
<link rel="stylesheet" href="/fancy-article-element.css">
261+
<link rel="stylesheet" href="/fancy-article-element.css" />
264262
```
265263

266264
If you do this, the stylesheet will be loaded after the script is loaded. This will likely cause a “flash of unstyled
267265
content” (FOUC). To circumvent this, you can preload the stylesheet like this:
268266

269267
```html
270-
<link rel="preload" href="/fancy-article-element.css" as="style">
268+
<link rel="preload" href="/fancy-article-element.css" as="style" />
271269
```
272270

273271
### Using Constructable Stylesheets
@@ -286,7 +284,7 @@ stylesheet.replaceSync(`
286284

287285
class FancyArticleElement extends HTMLElement {
288286
connectedCallback() {
289-
this.attachShadow({mode: 'open'}).adoptedStyleSheets = [stylesheet]
287+
this.attachShadow({ mode: "open" }).adoptedStyleSheets = [stylesheet]
290288
}
291289
}
292290
```
@@ -298,13 +296,13 @@ assertion where the `type` is `css` and then you can add the imported stylesheet
298296
the element’s shadow root.
299297

300298
```js
301-
import stylesheet from './fancy-article-element.css' assert { type: 'css' }
299+
import stylesheet from "./fancy-article-element.css" assert { type: "css" }
302300

303301
class FancyArticleElement extends HTMLElement {
304302
connectedCallback() {
305-
this.attachShadow({mode: 'open'}).adoptedStyleSheets = [stylesheet]
303+
this.attachShadow({ mode: "open" }).adoptedStyleSheets = [stylesheet]
306304
}
307305
}
308306
```
309307

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

Comments
 (0)