0
0
Tailwindmarkup~20 mins

@apply for extracting patterns in Tailwind - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tailwind @apply Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
Correct use of @apply in Tailwind CSS
Which option correctly uses @apply to extract common utility classes into a custom class?
Tailwind
/* Tailwind CSS file */
.btn-primary {
  @apply bg-blue-500 text-white font-bold py-2 px-4 rounded;
}
A.btn-primary { @apply(bg-blue-500 text-white font-bold py-2 px-4 rounded); }
B.btn-primary { apply: bg-blue-500 text-white font-bold py-2 px-4 rounded; }
C.btn-primary { @apply: bg-blue-500 text-white font-bold py-2 px-4 rounded; }
D.btn-primary { @apply bg-blue-500 text-white font-bold py-2 px-4 rounded; }
Attempts:
2 left
💡 Hint
Remember that @apply is a directive and does not use colons or parentheses.
rendering
intermediate
2:00remaining
Visual result of using @apply for button styles
Given the CSS below, what will the button look like in the browser?
Tailwind
.btn {
  @apply bg-green-600 text-white font-semibold py-3 px-6 rounded-lg hover:bg-green-700;
}
<button class="btn">Click me</button>
AA green button with white bold text, rounded corners, and a darker green hover effect.
BA blue button with white text and square corners, no hover effect.
CA button with default browser styles, no colors or rounding.
DA red button with black text and no hover effect.
Attempts:
2 left
💡 Hint
Look at the color classes and hover state applied.
selector
advanced
2:00remaining
Which selector correctly applies @apply to multiple classes?
You want to create a reusable style for both .card and .panel classes using @apply. Which CSS snippet is correct?
A.card, .panel { @apply bg-white shadow-md rounded p-4; }
B.card & .panel { @apply bg-white shadow-md rounded p-4; }
C.card .panel { @apply bg-white shadow-md rounded p-4; }
D.card; .panel { @apply bg-white shadow-md rounded p-4; }
Attempts:
2 left
💡 Hint
Think about how to select multiple classes in CSS.
layout
advanced
2:00remaining
Using @apply to create a responsive grid container
Which option correctly uses @apply to create a responsive grid with 3 columns on medium screens and above, and 1 column on small screens?
A.grid-container { @apply grid grid-cols-3 md:grid-cols-1 gap-4; }
B.grid-container { @apply grid grid-cols-1 md:grid-cols-3 gap-4; }
C.grid-container { @apply grid-cols-3 grid-cols-1 md:grid-cols-3 gap-4; }
D.grid-container { @apply grid-cols-1 grid md:grid-cols-3 gap-4; }
Attempts:
2 left
💡 Hint
Remember the order and syntax for responsive prefixes in Tailwind.
accessibility
expert
3:00remaining
Ensuring accessible focus styles with @apply
You want to create a custom button style that includes a visible focus ring for keyboard users using @apply. Which option correctly includes an accessible focus style?
A.btn { @apply bg-blue-600 text-white py-2 px-4 rounded focus:outline-none; }
B.btn { @apply bg-blue-600 text-white py-2 px-4 rounded focus:ring-0; }
C.btn { @apply bg-blue-600 text-white py-2 px-4 rounded focus:outline-none focus:ring-2 focus:ring-blue-300; }
D.btn { @apply bg-blue-600 text-white py-2 px-4 rounded; }
Attempts:
2 left
💡 Hint
Focus rings help keyboard users see which element is focused.