Complete the code to apply a scoped style to the paragraph.
<style>
p [1] {
color: blue;
}
</style>
<p>This text should be blue only inside this component.</p>In Svelte, styles inside the <style> tag are scoped by default. So just using p applies styles only to this component.
Complete the code to apply a global style to all paragraphs.
<style>
[1] {
font-weight: bold;
}
</style>
<p>This text should be bold everywhere.</p>Using :global(p) applies the style to all <p> elements globally, not just inside this component.
Fix the error in the style to make the button color red globally.
<style>
button [1] {
color: red;
}
</style>
<button>Click me</button>To make the button style global, wrap the selector with :global(). Other options are invalid or scope styles locally.
Complete the code to create a global style for links and a scoped style for headings.
<style>
a[1] {
text-decoration: none;
}
h1 {
color: green;
}
</style>Use :global() for the link style to apply globally. For the heading, no special selector is needed because styles are scoped by default.
Fill both blanks to style a global class, a scoped id, and a global element.
<style> .[1] { background: yellow; } #[2] { border: 1px solid black; } button { padding: 0.5rem; } </style>
The class highlight is styled globally by default with the dot. The id uses :global() to apply globally. The empty string means no extra selector for the id, so it is scoped by default.