0
0
NextJSframework~20 mins

Tailwind CSS integration in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tailwind CSS Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the visual output of this Next.js component using Tailwind CSS?

Consider this Next.js functional component styled with Tailwind CSS classes. What will the user see when this component renders?

NextJS
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>
  )
}
AA plain button with default browser styling
BA blue button with white bold text that darkens on hover and has rounded corners
CA red button with white text and square corners
DA button with blue text on white background and no hover effect
Attempts:
2 left
💡 Hint

Look at the Tailwind classes: bg-blue-600, hover:bg-blue-800, text-white, and rounded.

📝 Syntax
intermediate
1:30remaining
Which Tailwind CSS setup file is required for Next.js to enable custom styles?

In a Next.js project, which file must you create or modify to include Tailwind CSS directives for your styles?

Anext.config.js with Tailwind CSS plugin configuration
Bpages/_app.js with Tailwind CSS import statements
Ctailwind.config.js with CSS rules inside
Dstyles/globals.css with Tailwind directives like @tailwind base; @tailwind components; @tailwind utilities;
Attempts:
2 left
💡 Hint

Think about where CSS directives are placed to load Tailwind styles globally.

🔧 Debug
advanced
2:00remaining
Why does this Next.js component not apply Tailwind styles correctly?

Given this component, why might the Tailwind CSS classes not style the button as expected?

NextJS
export default function MyButton() {
  return (
    <button className="bg-green-500 text-white p-3 rounded">
      Press me
    </button>
  )
}
AThe attribute should be className, not class, in JSX
BThe p-3 class is invalid and causes styles to break
CThe button element must be wrapped in a div for Tailwind to work
DTailwind CSS does not support bg-green-500 class
Attempts:
2 left
💡 Hint

Remember how JSX handles HTML attributes differently.

state_output
advanced
2:00remaining
What is the button text after clicking in this Next.js component styled with Tailwind?

Review this component that toggles button text and styles on click. What text will the button show after the first click?

NextJS
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>
  );
}
A"Active" with gray background and black text
B"Inactive" with gray background and black text
C"Active" with red background and white text
D"Inactive" with red background and white text
Attempts:
2 left
💡 Hint

Check how the active state toggles and affects text and classes.

🧠 Conceptual
expert
2:30remaining
Which Tailwind CSS feature enables conditional styling in Next.js components without inline styles?

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?

AUsing the <code>clsx</code> or <code>classnames</code> utility libraries to conditionally join class names
BWriting multiple CSS files and importing them conditionally
CUsing inline <code>style</code> attributes with JavaScript objects
DModifying the tailwind.config.js file dynamically at runtime
Attempts:
2 left
💡 Hint

Think about how to manage class names cleanly in React components.