@apply to extract common utility classes into a custom class?/* Tailwind CSS file */
.btn-primary {
@apply bg-blue-500 text-white font-bold py-2 px-4 rounded;
}@apply is a directive and does not use colons or parentheses.The @apply directive in Tailwind CSS is used inside CSS rules without a colon or parentheses. Option D shows the correct syntax.
.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>The @apply directive adds the Tailwind utility classes to the .btn class. This results in a green background, white text, rounded corners, and a hover effect that darkens the green.
.card and .panel classes using @apply. Which CSS snippet is correct?Option A correctly uses a comma to select both .card and .panel classes and applies the styles with @apply. Other options use invalid or incorrect selectors.
@apply to create a responsive grid with 3 columns on medium screens and above, and 1 column on small screens?Option B correctly applies a grid layout with 1 column by default and switches to 3 columns on medium screens using the md: prefix. Other options misuse the order or syntax.
@apply. Which option correctly includes an accessible focus style?Option C includes focus:outline-none to remove default outline and adds a visible focus ring with focus:ring-2 focus:ring-blue-300. This ensures the button is accessible for keyboard navigation. Other options remove or omit focus styles.