-
Notifications
You must be signed in to change notification settings - Fork 537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use css variables defined in css file in UI #2270
Comments
Hi Mariuz, You can reference your CSS variables in Tailwind CSS by using the var() function. You would write the class like this: bg-[var(--primary)] This way, the Card component will use the --primary variable defined in your CSS file for the background color. Just make sure your CSS variables are defined correctly and the styles are applied as expected! Let me know if you have any further questions! |
This could be 2 different issues, wrong tailwind syntax and styling specificity or just one of them. Example 2 is wrong from the syntax POV but i guess the color result is what you want event though this seems to be accidental. For starters, try to remove the color property and write the class with the var function with referencing the variable. This should work for primary color: Hello In case it does not try this: Hello Let me know if this helped. |
Github formatted the syntax, here it is: 'Hello' 'Hello' |
Hm sorry I'm confused so just adding |
Yes ! means important. Okay now that we solved the syntax we need to solve the specificity. Basically there is an easy way to do this for tailwind using this helper: https://github.com/ccxdev/cn-func That way always the classes passed after will override the ones before and there should never be any specificity problems. Let me know if you need more help. |
Hi MariuzM, I hope the answer above helped you. If you need further help let me know, Otherwise, please mark the answer as accepted. Thanks. |
I'm not really a fan that i need to use ! to override the style. feels like this is after thought on the UI lib. It should just make sense any styles i pass should already override the existing ones by default |
Hi @MariuzM , If you use the cn helper in that case there is no need to ever use ! important for specificity. Before we were only using it to see if that was the issue. Meaning that if you do something like const className = cn("bg-red-500", "bg-blue-500") Blue color will be used as the helper will always correctly override previos tailwind classes with the new ones being passed after. Let me know if this helps. |
Description
I have defined some css variables in css file that is located in
app/styles/main.css location
. I can use these in tw like sobg-[--primary]
but how do i use this with
UI
lib ? for example using with Card component?The text was updated successfully, but these errors were encountered: