Potential CSS variable clashes #18759
-
I was wondering if anyone had a decent solution/workaround for the issue presented in this minimal repro: https://play.tailwindcss.com/r2MZIwUdVm?file=css Assume that your application imports some package that defines its own css variables inside some container. We can reasonably assume that a common naming convention might be --color-whatever. If your host application happens to define a color variant with the same name, you'll end up having a clash as shown in the play snippet above. I understand this is not a bug or an issue with tailwind itself and what I see is basically the expected behavior. The generated css is @layer utilities {
.text-danger {
color: var(--color-danger);
}
} And --color-danger is orange inside that specific container, so that's what it will resolve to. I understand that. However:
I'm guessing the cleanest solution would be to have "package" namespace (eg prefix) its variables. That, however, can be rather problematic if said package has tons of variables all over the place, requiring a bigger effort in terms of a refactor. And if you don't have ownership of it, then you're SOL, I guess. You could of course override these variables inside the container from your host app too: .package {
--color-danger: red;
} But then:
It might sound like a contrived example at first but I think this is at least a legitimate question to raise. Does anyone have a "good" solution for this? Would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
You could consider bypassing CSS variables entirely using the |
Beta Was this translation helpful? Give feedback.
You'd use an arbitrary property class like: