Having trouble understanding @utility override based on theme #18756
Answered
by
wongjn
LarsWesselius
asked this question in
Help
-
Hi! I'm looking for a suggested approach for a situation where I only want the light variant of my theme (specified by using data-theme attrib) to have a border on the sidebar (with class .sidebar). I have a custom variant for each of themes specified. Here's the full CSS @import "tailwindcss";
@plugin "@tailwindcss/typography";
@plugin "@tailwindcss/forms";
/*@custom-variant dark (&:where(.dark, .dark *));*/
@custom-variant light (&:where([data-theme=light], [data-theme=light] *));
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
@custom-variant colorful (&:where([data-theme=colorful], [data-theme=colorful] *));
@custom-variant purple (&:where([data-theme=purple], [data-theme=purple] *));
@theme {
...
}
@theme inline {
--color-primary-800: var(--primary-800);
...
}
/*
@utility sidebar {
@variant light {
@apply border-r border-gray-200;
}
}*/
/*
@layer components {
@variant light {
.sidebar {
@apply border-r border-gray-200;
}
}
}*/
@layer base {
[data-theme='light'] {
--primary-800: var(--color-gray-50);
.sidebar {
@apply border-r border-gray-200;
}
}
[data-theme='dark'] {
--primary-800: var(--color-gray-900);
...
}
[data-theme='purple'] {
--primary-800: oklch(0.1532 0.0847 293.81);
...
}
} I have a couple of questions;
Thanks so much! |
Beta Was this translation helpful? Give feedback.
Answered by
wongjn
Aug 18, 2025
Replies: 1 comment
-
Adam Wathan (creator of Tailwind) does seem to advocate avoiding
Instead, consider setting the Tailwind class names directly in the template like: <div class="… light:border-r light:border-gray-200"> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
LarsWesselius
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adam Wathan (creator of Tailwind) does seem to advocate avoiding
@apply
:Instead, consider setting the Tailwind class names directly in the template like: