Skip to content

Commit f5f5846

Browse files
committed
documentation
1 parent 492a9b6 commit f5f5846

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This works by adding a class to affected elements, which is based on a hash of t
2525
</style>
2626
```
2727

28-
## :global
28+
## :global(...)
2929

3030
To apply styles to a selector globally, use the `:global(...)` modifier.
3131

@@ -66,6 +66,34 @@ The `-global-` part will be removed when compiled, and the keyframe will then be
6666
</style>
6767
```
6868

69+
## :global
70+
71+
To apply all styles after a certain point to a selector globally, use the `:global` modifier.
72+
73+
```svelte
74+
<style>
75+
: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+
}
84+
}
85+
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;
91+
}
92+
</style>
93+
```
94+
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+
6997
## Nested style tags
7098

7199
There should only be 1 top-level `<style>` tag per component.

0 commit comments

Comments
 (0)