Consider this Svelte component style block using SCSS:
<style lang="scss">
.parent {
color: blue;
.child {
color: red;
}
}
</style>What CSS will be generated and applied to the component?
<style lang="scss">
.parent {
color: blue;
.child {
color: red;
}
}
</style>Think about how SCSS nesting combines selectors.
SCSS nesting combines selectors so .child inside .parent becomes .parent .child. The parent style applies to .parent only.
Given a Svelte component using PostCSS, which style block syntax is correct?
PostCSS supports CSS variables and standard CSS syntax.
Option A uses valid CSS variable declaration inside a PostCSS block. Option A misuses @apply with a variable, which is invalid. Option A uses wrong lang and invalid syntax. Option A misses semicolon causing syntax error.
Given this Svelte component style block:
<style lang="scss">
.button {
color: green;
&:hover {
color: darkgreen;
}
}
</style>Why does the hover style not work?
<style lang="scss">
.button {
color: green
&:hover {
color: darkgreen;
}
}
</style>Check SCSS syntax carefully for missing punctuation.
SCSS requires semicolons after property declarations. Missing semicolon after 'color: green' causes the whole block to fail compiling, so nested hover styles do not apply.
Consider this style block in a Svelte component using PostCSS with autoprefixer enabled:
<style lang="postcss">
.example {
display: flex;
}
</style>What CSS will be output to support older browsers?
<style lang="postcss">
.example {
display: flex;
}
</style>Autoprefixer adds vendor prefixes for compatibility.
Autoprefixer adds vendor prefixes like -webkit-box and -ms-flexbox before the standard flex to support older browsers.
In Svelte, when using lang="scss" in a style block, how does Svelte ensure styles are scoped only to the component?
Think about how Svelte compiles components and styles.
Svelte preprocesses SCSS to CSS, then adds unique data attributes to component elements and rewrites selectors to include these attributes, ensuring styles apply only inside the component.