Skip to content
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

bug: CSS variables set in typography plugin settings are overriden #2957

Closed
dhnm opened this issue Apr 4, 2024 · 2 comments
Closed

bug: CSS variables set in typography plugin settings are overriden #2957

dhnm opened this issue Apr 4, 2024 · 2 comments

Comments

@dhnm
Copy link

dhnm commented Apr 4, 2024

What version of daisyUI are you using?

v4.7.2

Which browsers are you seeing the problem on?

All browsers

Reproduction URL

https://play.tailwindcss.com/r5c431Gu2Y?file=config

Describe your issue

I am using tailwind/typography plugin.

I want to define CSS variables in the tailwind config file for the plugin:

module.exports = {
  theme: {
      typography: {
        DEFAULT: {
          css: {
            "--tw-prose-body": "red",
            color: "var(--tw-prose-body)"
          }
        }
      }
  },
  plugins: [require("@tailwindcss/typography"), require('daisyui')]
}

This doesn't work, the text won't become red, but DaisyUI's settings will be applied instead.

Tailwind creates the following CSS:

/* Generated by Tailwind */
.prose {
  --tw-prose-body: "red";
}

The issue arises because DaisyUI creates the same variables that override tailwind ones like so:

/* Generated by DaisyUI */
:root .prose {
  --tw-prose-body: var(--fallback-bc,oklch(var(--bc)/0.8));
}
Copy link

github-actions bot commented Apr 4, 2024

Thank you @dhnm for reporting issues. It helps daisyUI a lot 💚
I'll be working on issues one by one. I will help with this one as soon as a I find a solution.
In the meantime providing more details and reproduction links would be helpful.

@saadeghi
Copy link
Owner

saadeghi commented Apr 4, 2024

daisyUI overrides the default colors coming from Typography plugin because otherwise, the colors will not adopt daisyUI themes. They will be the same color unless changed manually for each theme.

To override the CSS variable color manually you can do it from CSS like this:
https://play.tailwindcss.com/bgo17PqVB3?file=css

:root .prose{
  --tw-prose-body: red;
}

Or if you want to do it from the config file, using the JS object you can use !important (the reason is, Tailwind CSS puts styles from this object in a :where selector and it has low specificity so without !important it will not override the daisyUI colors)
https://play.tailwindcss.com/ahpNI7Dx66?file=config

Let me know if you have a question.

@saadeghi saadeghi closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants