Complete the code to define a scoped style inside a Svelte component.
<style>[1]
p {
color: blue;
}
</style>Using module inside the <style> tag scopes the CSS to the component in Svelte.
Complete the code to apply a dynamic style using a Svelte reactive variable.
<script> let color = 'red'; </script> <p style="color: [1]">This text is colored.</p>
In Svelte, to use a variable inside an attribute, you wrap it in curly braces like {color}.
Fix the error in the code to correctly bind a CSS variable to a Svelte component style.
<script> let bgColor = 'lightblue'; </script> <div style="--bg: [1]; background-color: var(--bg);"> Colored box </div>
When binding a variable inside a style attribute in Svelte, you need to use curly braces without spaces: {bgColor}.
Fill both blanks to create a reactive style block that updates the CSS variable when the color changes.
<script> let color = 'green'; $: [1] = `--main-color: ${color}`; </script> <div style=[2]> Dynamic color box </div>
The reactive statement assigns a string to styleString, which is then used in the style attribute of the div.
Fill all three blanks to create a Svelte component that uses CSS-in-JS with a reactive style and scoped CSS module.
<script> let size = 100; $: [1] = `width: ${size}px; height: ${size}px; background: coral;`; </script> <style module> .box { border-radius: 8px; [2] } </style> <div class=[3] style=[1]> Stylish box </div>
The reactive variable styleString holds inline styles. The scoped CSS module class box is applied to the div. The CSS inside the module adds white text color.