Consider a Next.js component styled with CSS Modules. What is the main effect of using CSS Modules on the component's styles?
import styles from './Button.module.css'; export default function Button() { return <button className={styles.primary}>Click me</button>; }
Think about how CSS Modules prevent style clashes by scoping.
CSS Modules generate unique class names scoped to the component, so styles do not leak or conflict globally.
Next.js supports various styling options. Which method allows you to use JavaScript variables directly to change styles dynamically?
Look for the styling method that supports embedding JS expressions inside styles.
Styled JSX allows writing CSS inside components with support for JavaScript expressions, enabling dynamic styling.
Given this Next.js component, why does the button not get the expected red background?
import styles from './Button.module.css'; export default function Button() { return <button className="styles.redBackground">Press me</button>; } /* Button.module.css */ .redBackground { background-color: red; }
Check how className is assigned in JSX when using CSS Modules.
When using CSS Modules, className must be set with curly braces to reference the imported styles object, not as a string.
Tailwind CSS is popular with Next.js projects. What is a main advantage of using Tailwind CSS compared to writing traditional CSS files?
Think about how Tailwind changes the way you write styles.
Tailwind offers ready-made utility classes that let you style elements quickly without writing separate CSS files.
Consider this Next.js component using styled-jsx with a dynamic color prop. What color will the button text be when rendered?
export default function ColorButton({ color }) { return ( <> <button>Click me</button> <style jsx>{` button { color: ${color}; } `}</style> </> ); } // Usage: <ColorButton color="blue" />
Check how styled-jsx supports JavaScript variables inside styles.
Styled-jsx allows embedding JavaScript variables inside CSS using template literals, so the color prop sets the button text color.