0
0
Svelteframework~20 mins

Preprocessor support (SCSS, PostCSS) in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Preprocessor Pro in Svelte
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does SCSS nesting affect Svelte component styles?

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?

Svelte
<style lang="scss">
.parent {
  color: blue;
  .child {
    color: red;
  }
}
</style>
A.parent { color: blue; } .child { color: red; }
B.child { color: blue; } .parent { color: red; }
C.parent { color: blue; } .parent .child { color: red; }
D.parent .child { color: blue; } .child { color: red; }
Attempts:
2 left
💡 Hint

Think about how SCSS nesting combines selectors.

📝 Syntax
intermediate
2:00remaining
Which PostCSS syntax is valid in a Svelte style block?

Given a Svelte component using PostCSS, which style block syntax is correct?

A
&lt;style lang="postcss"&gt;
:root {
  --main-color: #06c;
}
&lt;/style&gt;
B
&lt;style lang="postcss"&gt;
@apply --main-color;
&lt;/style&gt;
C
&lt;style lang="css"&gt;
@apply --main-color;
&lt;/style&gt;
D
&lt;style lang="postcss"&gt;
:root {
  --main-color: #06c
}
&lt;/style&gt;
Attempts:
2 left
💡 Hint

PostCSS supports CSS variables and standard CSS syntax.

🔧 Debug
advanced
2:00remaining
Why does this SCSS style not apply in Svelte?

Given this Svelte component style block:

<style lang="scss">
.button {
  color: green;
  &:hover {
    color: darkgreen;
  }
}
</style>

Why does the hover style not work?

Svelte
<style lang="scss">
.button {
  color: green
  &:hover {
    color: darkgreen;
  }
}
</style>
ASvelte does not support nested selectors in SCSS style blocks.
BMissing semicolon after 'color: green' causes SCSS compile error, so hover style is ignored.
CThe hover selector must be written as '.button:hover' outside nesting.
DThe color 'darkgreen' is invalid and ignored by the browser.
Attempts:
2 left
💡 Hint

Check SCSS syntax carefully for missing punctuation.

state_output
advanced
2:00remaining
What is the effect of PostCSS autoprefixer in Svelte styles?

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?

Svelte
<style lang="postcss">
.example {
  display: flex;
}
</style>
A.example { display: grid; }
B.example { display: flex; }
C.example { display: block; }
D.example { display: -webkit-box; display: -ms-flexbox; display: flex; }
Attempts:
2 left
💡 Hint

Autoprefixer adds vendor prefixes for compatibility.

🧠 Conceptual
expert
3:00remaining
How does Svelte handle scoped styles with SCSS preprocessing?

In Svelte, when using lang="scss" in a style block, how does Svelte ensure styles are scoped only to the component?

ASvelte adds unique data attributes to elements and rewrites SCSS selectors to include these attributes after preprocessing.
BSCSS automatically scopes styles by prefixing selectors with the component name.
CSvelte wraps the component in a shadow DOM to isolate styles when using SCSS.
DSvelte requires manual addition of unique classes in SCSS to scope styles.
Attempts:
2 left
💡 Hint

Think about how Svelte compiles components and styles.