daisyui icon indicating copy to clipboard operation
daisyui copied to clipboard

bug: !important needed to override some styles in DaisyUI

Open withden opened this issue 11 months ago • 6 comments

In some cases, DaisyUI styles require important overrides, which can cause issues when customizing styles.

If you've faced similar issues where DaisyUI styles are difficult to override, please comment below with the class. We will add into this list

Bug List

  • [ ] Badge (badge badge-outline !border-base-300)

withden avatar Mar 12 '25 13:03 withden

Thank you @withden 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.

github-actions[bot] avatar Mar 12 '25 13:03 github-actions[bot]

Hello @withden,

The reason for this is that in Tailwind V4, the addComponents function now places the CSS under @layer utilities.

Image

As for the DaisyUI style for badges, the border color of the outline badge uses the current text color. Instead of modifying the border, you should adjust the text color like this:

text-base-300

This issue will persist until Tailwind Labs decides to revert the changes. @saadeghi has also raised this issue in Tailwind:
https://github.com/tailwindlabs/tailwindcss/issues/15045

PruthviPraj00 avatar Mar 13 '25 05:03 PruthviPraj00

Yes! This is also what I ran into. I just came from https://github.com/tailwindlabs/tailwindcss/issues/15045, wish this could be fixed as fast as they could. I override the .btn class of v5, made it hover:scale-95 and translate-none. If I let it go with the utilities layer, it just won't override.

@import "tailwindcss";
@plugin "daisyui";

@layer base, components, utilities, daisyui-override;

@layer daisyui-override {
  .btn {
    @apply translate-none;

    transition: scale 0.1s ease-in-out;
    
    &:hover {
      @apply active:scale-95;
    }
  }

  & .btn-ghost {
    /* --btn-ghost-bg: oklch(from var(--color-base-content) l c h / calc(alpha - 0.8)); */
    --btn-ghost-bg: color-mix(in oklab, var(--color-base-content), transparent 80%);

    &:hover {
      --btn-bg: color-mix(in oklab, var(--btn-color, var(--btn-ghost-bg)), black 7%);
    }

    &:active:not(.btn-active) {
      --btn-bg: color-mix(in oklab, var(--btn-color, var(--btn-ghost-bg)), black 5%);
      --btn-border: color-mix(in oklab, var(--btn-color, var(--btn-ghost-bg)), black 7%);
    }
  }
}

CoderJo-Pro avatar Apr 04 '25 08:04 CoderJo-Pro

Hey,

@saadeghi I face this issue again with the latest changes in the badge component.

withden avatar Apr 25 '25 09:04 withden

@withden for border color?

saadeghi avatar Apr 25 '25 09:04 saadeghi

Yes, for border-color, we need to use !border-base-300 (it will work with important)

withden avatar Apr 25 '25 09:04 withden

Hi, Is my first time using DaisyUi and I just tried a very basic customization as shown in the customize docs:

<button class="btn rounded-full">rounded-full not working</button>
<button class="btn rounded-full!">rounded-full working</button>

I expected rounded-full to override the button’s border radius. However, it only works when I add the ! (important) modifier: rounded-full!.

Is this a temporal default/expected behavior due to the Tailwind v4 change described in https://github.com/tailwindlabs/tailwindcss/issues/15045? or should this work without the important override and I’m missing something?

Thanks!

lemachinarbo avatar Aug 16 '25 17:08 lemachinarbo

@lemachinarbo rounded-full work as expected:
https://play.tailwindcss.com/7yFvAsKZ5j

There are only a few cases where ! is needed. For example the case in this issue. Simple customizations like rounded-full is not one of them.
If rounded-full is not working please share a minimal reproduction so I can help.

saadeghi avatar Aug 16 '25 17:08 saadeghi

Thanks for the quick response @saadeghi

It might be a bundling issue? I’m using Rspack I’ll test and report back if I find anything relevant. In case you’re curious, I created this minimal example: https://codesandbox.io/p/devbox/3ldt2t

lemachinarbo avatar Aug 16 '25 21:08 lemachinarbo

@lemachinarbo Thanks for the link.
Yes seems like it is a bundler issue!
Looking at the output CSS:

Image

It is changing the style, adding those .btn:not(:is(:lang(ae), :lang(ar)... with higher while it should be just .btn! Those selectors are not from daisyUI.

I couldn't reproduce the same issue with a fresh setup tho. It works with that setup 🤔

saadeghi avatar Aug 16 '25 23:08 saadeghi

I think this can be closed

  • the original problem should now be fixed in 5.3.0
  • the other problems are related to bundlers/CSS processors not related to DaisyUI

pdanpdan avatar Oct 13 '25 22:10 pdanpdan