Custom functional utility with color values #18041
Answered
by
wongjn
jacksleight
asked this question in
Help
-
What's the correct way to write a custom functional utility that uses color and opacity values? I have this: @utility overlay-* {
border-image: linear-gradient(to top, --value(--color-*), --value(--color-*)) fill 1;
} Which works when called with .overlay-black {
border-image: linear-gradient(to top, var(--color-black), var(--color-black)) fill 1;
} But when called with an opacity as |
Beta Was this translation helpful? Give feedback.
Answered by
wongjn
May 15, 2025
Replies: 1 comment 1 reply
-
@utility overlay-* {
--alpha: calc(1% * --modifier(integer));
--color: --alpha(--value(--color-*) / var(--alpha, 100%));
border-image: linear-gradient(to top, var(--color), var(--color)) fill 1;
}
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jacksleight
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
--modifier()
is where the value after the slash. If there is no slash, the declaration is removed.--alpha()
is Tailwind syntax sugar forcolor-mix()
.https://play.tailwindcss.com/BAEVBTPuJc