ui icon indicating copy to clipboard operation
ui copied to clipboard

opacity issues with tailwind bg #560

Open areebbbb opened this issue 2 years ago • 6 comments

areebbbb avatar Jun 09 '23 16:06 areebbbb

Someone is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 09 '23 16:06 vercel[bot]

Interesting, please provide a brief description of the improvement so that I can understand it better. I think it's a great option to be able to give opacity using the following format if I'm not mistaken: border-[#ff0000/50]

jocarrd avatar Jun 09 '23 17:06 jocarrd

yes, you are right it could be done that way but the problem is when we are using pre-defined variables and changing their opacity it runs into issues and in this project, we are using hsl format which is not compatible which what you are suggesting.

currently after update image previously before update which would not work image

areebbbb avatar Jun 09 '23 19:06 areebbbb

I still don't understand why not just use bg-[#ff0000]/50

dan5py avatar Jun 11 '23 17:06 dan5py

it will work fine in this way but we are using hsl variables in this project either we have to use hex variable or for hsl we would need to change to legacy way of tailwind cause bg-primary/90 will not work with hsl variables

areebbbb avatar Jun 11 '23 20:06 areebbbb

So tell me if I got it right:

You want to use bg-primary/90 with this configuration:

/* globals.css */
@layer base {
  :root {
    --primary: 222.2 47.4% 11.2%;
  } 
}
/* tailwind.config.js*/
colors: {
        primary: {
          DEFAULT: "hsl(var(--primary))",
          foreground: "hsl(var(--primary-foreground))",
        },
}

dan5py avatar Jun 11 '23 21:06 dan5py

you are right I want to use it with this configuration but the issue is that hsl takes opacity inside the brackets so if we are using it inside this way the opacity will not work

...
.hover\:bg-primary\/50:hover {
    background-color: hsl(var(--primary)) / 0.5;
}

...
...
.hover\:bg-primary\/50:hover {
    background-color: hsl(var(--primary) / 0.5);
}

...

it works this way

...
.hover\:bg-primary\/50:hover {
    background-color: hsl(var(--primary), 0.5);
}
...

areebbbb avatar Jun 12 '23 20:06 areebbbb

This is the modern hsl syntax (and it works just fine):

...
.hover\:bg-primary\/50:hover {
    background-color: hsl(var(--primary) / 0.5);
}
...

When you set the opacity with bg-primary/50, that's the generated code. Check it in this Tailwind Playground.

dan5py avatar Jun 13 '23 10:06 dan5py

It is working in the playground but it is not working in my project I had to use the other but thanks

areebbbb avatar Jun 13 '23 20:06 areebbbb

I'm having the exact same problem. What fixed for me was changing the tailwind.config.ts colors from hsl(var(--primary)) to hsla(var(--primary))

samuelpetroline avatar Jun 19 '23 20:06 samuelpetroline

should we create a PR about it or something?

areebbbb avatar Jun 24 '23 00:06 areebbbb

I'm having the exact same problem. What fixed for me was changing the tailwind.config.ts colors from hsl(var(--primary)) to hsla(var(--primary))

i was facing this bg opacity issue. but after using hsla(), it's fixed! now my background-color working fine with opacity

mamlzy avatar Jun 27 '23 07:06 mamlzy