Skip to content

Color alpha #360

Answered by saadeghi
mmpneo asked this question in Q&A
Discussion options

You must be logged in to vote

Alpha is not technically a part of color value. It's the opacity of color and since Tailwind has utility classes for opacity, I'm not sure if there's a better way to handle opacity. Even with Tailwind's original colors, when we use bg-green-500 This is the generated CSS:

.bg-green-500 {
  --tw-bg-opacity: 1;
  background-color: rgba(16, 185, 129, var(--tw-bg-opacity));
}

I'm applying the same method with daisyUI colors. except I use HSLA and CSS variables:

:root {
  --p: 259 94.4% 51.2%;
}
.bg-primary {
  --tw-bg-opacity: 1;
  background-color: hsla(var(--p) / var(--tw-bg-opacity));
}

This is also suggested by Tailwind team.
But if you know a better way to handle colors, I'll be glad.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by saadeghi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants