Skip to content

Commit 8ba8511

Browse files
committed
tweak docs
1 parent 7c640ee commit 8ba8511

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

documentation/docs/02-template-syntax/05-styles-and-classes.md

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ To apply styles to a selector globally, use the `:global(...)` modifier.
3232
```svelte
3333
<style>
3434
:global(body) {
35-
/* this will apply to <body> */
35+
/* applies to <body> */
3636
margin: 0;
3737
}
3838
3939
div :global(strong) {
40-
/* this will apply to all <strong> elements, in any
41-
component, that are inside <div> elements belonging
42-
to this component */
40+
/* applies to all <strong> elements, in any
41+
component, that are inside <div> elements belonging
42+
to this component */
4343
color: goldenrod;
4444
}
4545
4646
p:global(.red) {
47-
/* this will apply to all <p> elements belonging to this
48-
component with a class of red, even if class="red" does
49-
not initially appear in the markup, and is instead
50-
added at runtime. This is useful when the class
51-
of the element is dynamically applied, for instance
52-
when updating the element's classList property directly. */
47+
/* applies to all <p> elements belonging to this
48+
component with a class of red, even if class="red" does
49+
not initially appear in the markup, and is instead
50+
added at runtime. This is useful when the class
51+
of the element is dynamically applied, for instance
52+
when updating the element's classList property directly. */
5353
}
5454
</style>
5555
```
@@ -73,28 +73,22 @@ To apply all styles after a certain point to a selector globally, use the `:glob
7373
```svelte
7474
<style>
7575
:global {
76-
div {
77-
/* this will apply to every <div> in your application */
78-
margin: 0;
79-
}
80-
p {
81-
/* this will apply to every <p> in your application */
82-
color: blue;
83-
}
76+
/* applies to every <div> in your application */
77+
div { ... }
78+
79+
/* applies to every <p> in your application */
80+
p { ... }
8481
}
8582
86-
div :global strong {
87-
/* this will apply to all <strong> elements, in any
88-
component, that are inside <div> elements belonging
89-
to this component */
90-
color: goldenrod;
83+
.a :global {
84+
/* applies to every `.b .c .d` element, in any component,
85+
that is inside an `.a` element in this component */
86+
.b .c .d {...}
9187
}
9288
</style>
9389
```
9490

95-
The difference between `:global` and `:global(...)` is that `:global(...)` only makes all styles within its braces global, whereas `:global` makes all styles coming after it global, including those in nested CSS.
96-
97-
If `:global` is preceeded by a descendant combinator, the combinator is removed from the output. That means that `div :global.x` is equivalent to `div.svelte-hash.x`.
91+
> The second example above could also be turned into a `.a :global .b .c .d` selector, where everything after the `:global` is unscoped. Both forms are semantically equal, and as such this form is also supported, but the nested form is recommended instead when writing styles.
9892
9993
## Nested style tags
10094

0 commit comments

Comments
 (0)