Consider this Next.js functional component styled with Tailwind CSS classes. What will the user see when this component renders?
export default function Button() { return ( <button className="bg-blue-600 hover:bg-blue-800 text-white font-bold py-2 px-4 rounded"> Click me </button> ) }
Look at the Tailwind classes: bg-blue-600, hover:bg-blue-800, text-white, and rounded.
The button uses Tailwind classes to set a blue background that becomes darker on hover, white bold text, padding, and rounded corners.
In a Next.js project, which file must you create or modify to include Tailwind CSS directives for your styles?
Think about where CSS directives are placed to load Tailwind styles globally.
The globals.css file is where Tailwind's base, components, and utilities directives are added to apply styles globally.
Given this component, why might the Tailwind CSS classes not style the button as expected?
export default function MyButton() { return ( <button className="bg-green-500 text-white p-3 rounded"> Press me </button> ) }
Remember how JSX handles HTML attributes differently.
In JSX (used by Next.js), the HTML attribute class must be written as className to apply CSS classes.
Review this component that toggles button text and styles on click. What text will the button show after the first click?
import { useState } from 'react'; export default function ToggleButton() { const [active, setActive] = useState(false); return ( <button className={active ? 'bg-red-500 text-white' : 'bg-gray-300 text-black'} onClick={() => setActive(!active)} > {active ? 'Active' : 'Inactive'} </button> ); }
Check how the active state toggles and affects text and classes.
Initially active is false, so button shows "Inactive" with gray styling. After first click, active becomes true, changing text to "Active" and styles to red background with white text.
In Next.js with Tailwind CSS, how can you apply styles conditionally based on component state or props without using inline styles or manual string concatenation?
Think about how to manage class names cleanly in React components.
Libraries like clsx or classnames help conditionally combine Tailwind CSS classes based on state or props, avoiding messy string concatenation or inline styles.