Performance: @apply for extracting patterns
This affects CSS bundle size and browser rendering by reusing styles efficiently.
.btn-base { @apply px-4 py-2 rounded; } .btn-primary { @apply btn-base bg-blue-500 text-white; } .btn-secondary { @apply btn-base bg-gray-500 text-white; }.btn-primary { @apply bg-blue-500 text-white px-4 py-2 rounded; } .btn-secondary { @apply bg-gray-500 text-white px-4 py-2 rounded; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated utility classes without @apply | N/A | 0 | Medium due to larger CSS | [X] Bad |
| Extracted shared styles with @apply | N/A | 0 | Lower due to smaller CSS | [OK] Good |
@apply in Tailwind CSS?@apply does@apply lets you write multiple Tailwind utility classes inside a CSS rule to create a single custom class.@apply inside a CSS file?@apply syntax@apply followed by utility classes inside a CSS rule block.@apply correctly with utility classes separated by spaces.@apply:
.card {
@apply p-6 bg-white rounded-lg shadow-md;
}
What visual styles will the .card class have?p-6 means padding 1.5rem, bg-white sets white background, rounded-lg adds large rounded corners, shadow-md adds medium shadow.@apply?
.btn {
@apply text-white bg-blue-500 px-4 py-2;
@apply rounded-lg;
color: red;
}@apply that has white text, blue background, padding, rounded corners, and a hover effect that darkens the background. Which CSS snippet correctly achieves this?&:hover in your CSS.&:hover { @apply bg-blue-700; }. .btn {
@apply text-white bg-blue-500 px-4 py-2 rounded hover:bg-blue-700;
} tries to use hover:bg-blue-700 inside @apply which is invalid. Options C and D have incorrect hover selector syntax.Pass the test and this pattern moves unknown