0
0
Tailwindmarkup~20 mins

Tailwind with Next.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tailwind with Next.js Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
layout
intermediate
2:00remaining
Understanding Tailwind Flexbox in Next.js
You have a Next.js component using Tailwind CSS. What will be the visual layout of the boxes inside the container?

Code:
export default function FlexExample() {
  return (
    <div className="flex flex-col md:flex-row gap-4 p-4">
      <div className="bg-blue-500 text-white p-4">Box 1</div>
      <div className="bg-green-500 text-white p-4">Box 2</div>
      <div className="bg-red-500 text-white p-4">Box 3</div>
    </div>
  )
}
Tailwind
export default function FlexExample() {
  return (
    <div className="flex flex-col md:flex-row gap-4 p-4">
      <div className="bg-blue-500 text-white p-4">Box 1</div>
      <div className="bg-green-500 text-white p-4">Box 2</div>
      <div className="bg-red-500 text-white p-4">Box 3</div>
    </div>
  )
}
ABoxes are arranged horizontally side-by-side on all screen sizes.
BBoxes overlap each other because of conflicting flex classes.
CBoxes are stacked vertically on all screen sizes with no horizontal arrangement.
DBoxes are stacked vertically on small screens and arranged horizontally side-by-side on medium and larger screens.
Attempts:
2 left
💡 Hint
Look at the responsive prefix 'md:' in the class names and what flex-col and flex-row do.
accessibility
intermediate
2:00remaining
Improving Accessibility with Tailwind and Next.js
You want to make a button in a Next.js app styled with Tailwind accessible for screen readers. Which option correctly adds an accessible label to a button that only shows an icon visually?

Code snippet:
<button className="p-2 bg-gray-800 text-white rounded">
  <svg aria-hidden="true" className="w-6 h-6">...</svg>
</button>
Tailwind
<button className="p-2 bg-gray-800 text-white rounded">
  <svg aria-hidden="true" className="w-6 h-6">...</svg>
</button>
AAdd aria-label="Close menu" attribute to the button element.
BAdd <span className="sr-only">Close menu</span> inside the button after the SVG.
CAdd title="Close menu" attribute to the SVG element.
DAdd role="img" to the button element.
Attempts:
2 left
💡 Hint
Screen readers read aria-label on interactive elements like buttons.
📝 Syntax
advanced
2:00remaining
Tailwind Class Conditional Rendering in Next.js
You want to conditionally apply Tailwind classes in a Next.js component based on a boolean state. Which code snippet correctly applies 'bg-green-500' when isActive is true, and 'bg-red-500' when false?

Assume isActive is a boolean state variable.
Tailwind
export default function StatusButton({ isActive }) {
  return (
    <button className={/* fill here */ + " text-white p-2 rounded"}>
      Status
    </button>
  )
}
AclassName={`${isActive ? 'bg-green-500' : 'bg-red-500'} text-white p-2 rounded`}
BclassName={isActive && 'bg-green-500' || 'bg-red-500' + ' text-white p-2 rounded'}
CclassName={isActive ? 'bg-green-500 text-white p-2 rounded' : 'bg-red-500 text-white p-2 rounded'}
DclassName={['bg-green-500', 'bg-red-500'][isActive] + ' text-white p-2 rounded'}
Attempts:
2 left
💡 Hint
Use template literals and the ternary operator inside className.
selector
advanced
2:00remaining
Tailwind Customizing Focus Styles in Next.js
You want to customize the focus ring color on a button using Tailwind in Next.js. Which class combination correctly changes the focus ring to yellow with a 4px width?

Button base classes: p-3 rounded bg-blue-600 text-white
Tailwind
<button className="p-3 rounded bg-blue-600 text-white /* add focus classes here */">
  Click me
</button>
Afocus:outline-none focus:ring-4 focus:ring-yellow-400
Bfocus:outline focus:ring-yellow-400 focus:ring-4
Cfocus:ring focus:ring-yellow-400 focus:ring-4
Dfocus:ring-4 focus:ring-yellow-400 focus:outline-none
Attempts:
2 left
💡 Hint
Tailwind requires 'focus:ring' to enable the ring, then you can set size and color.
🧠 Conceptual
expert
3:00remaining
Next.js and Tailwind CSS: Optimizing for Production
In a Next.js project using Tailwind CSS, which configuration ensures the smallest CSS bundle size in production by removing unused styles?

Choose the correct Tailwind config snippet.
Tailwind
module.exports = {
  content: [/* fill here */],
  theme: {
    extend: {},
  },
  plugins: [],
}
Acontent: ['./src/**/*.{html,js}']
Bcontent: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}']
Ccontent: ['./public/**/*.{js,ts,jsx,tsx}']
Dcontent: ['./styles/**/*.{css,scss}']
Attempts:
2 left
💡 Hint
Tailwind scans files where you write JSX or HTML to find used classes.