0
0
Astroframework~20 mins

CSS Modules support in Astro - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Modules Mastery in Astro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does CSS Modules scope styles in Astro components?

Consider an Astro component using CSS Modules. What happens to the CSS class names when the component is rendered in the browser?

Astro
<style module>
.button {
  color: red;
}
</style>

<button class={styles.button}>Click me</button>
AThe class name is replaced with a unique hashed name to avoid conflicts.
BThe class name remains exactly as 'button' in the browser DOM.
CThe class name is removed and styles are applied inline instead.
DThe class name is prefixed with the component file name but otherwise unchanged.
Attempts:
2 left
💡 Hint

Think about how CSS Modules prevent style conflicts by changing class names.

📝 Syntax
intermediate
2:00remaining
Correct syntax to import CSS Modules in Astro

Which of the following is the correct way to import and use a CSS Module file named Button.module.css in an Astro component?

A
import './Button.module.css';
&lt;button class='button'&gt;Click&lt;/button&gt;
B
import styles from './Button.module.css';
&lt;button class={styles.button}&gt;Click&lt;/button&gt;
C
const styles = require('./Button.module.css');
&lt;button class={styles.button}&gt;Click&lt;/button&gt;
D
&lt;style module src='./Button.module.css'&gt;&lt;/style&gt;
&lt;button class={styles.button}&gt;Click&lt;/button&gt;
Attempts:
2 left
💡 Hint

Astro supports ES module imports for CSS Modules.

🔧 Debug
advanced
2:00remaining
Why does the CSS Module class not apply styles?

Given this Astro component code, the styles from the CSS Module are not applied. What is the most likely cause?

---
import styles from './Card.module.css';
---

Card content
AThe class attribute should use curly braces: <code>class={styles.card}</code> instead of quotes.
BThe CSS Module file must be named <code>Card.css</code> without <code>.module</code>.
CThe import statement should use require() instead of import.
DThe styles object is undefined because CSS Modules are not supported in Astro.
Attempts:
2 left
💡 Hint

Check how dynamic class names are passed in JSX-like syntax.

state_output
advanced
2:00remaining
What is the rendered class attribute value?

Given this Astro component using CSS Modules, what will be the exact value of the class attribute in the rendered HTML?

---
import styles from './Alert.module.css';
---

Warning!

Assume the original CSS class is alert and Astro generates a hash _Alert_alert_1a2b3.

A"styles.alert"
B"Alert_alert"
C"alert"
D"_Alert_alert_1a2b3"
Attempts:
2 left
💡 Hint

CSS Modules replace class names with unique hashed names.

🧠 Conceptual
expert
2:00remaining
Why use CSS Modules in Astro instead of global CSS?

Which of the following is the best explanation for why CSS Modules are preferred over global CSS in Astro projects?

ACSS Modules load styles faster because they are compiled to inline styles in the browser.
BGlobal CSS cannot be used in Astro projects because Astro does not support CSS files.
CCSS Modules automatically scope styles locally, preventing unintended style conflicts across components.
DCSS Modules allow writing CSS in JavaScript syntax, making styles easier to write.
Attempts:
2 left
💡 Hint

Think about how styles can accidentally affect other parts of a website.