[v4] color-mix utilities #14827
Replies: 3 comments 6 replies
-
This feature would be great, however maybe the syntax would need to account for a few things:
For example, what would happen in this case: <!-- is the mix applied to bg or to text color ? -->
<button class="bg-sky-600 text-slate-50 hover:mix-black/10">Click me</button> Or, with an alternate syntax: <!-- Are the color modifiers used as alpha values or mix percentages ? -->
<button class="bg-sky-600 text-slate-50 hover:bg-sky-600/75-mix-black/10">Click me</button> |
Beta Was this translation helpful? Give feedback.
-
The color-mix plugin in #13085 is broken in v4 because it can no longer capture I briefly tried working around the issue, but sadly found that default plugins cannot be extended or overriden. As far as I can tell, creating functional plugins like As such, I think there should be a native syntax for colors like this: <a class="bg-mix-in/srgb bg-sky/10 bg-mix-white/30">asdf</a> background-color: color-mix(in srgb, var(--color-sky) 10%, var(--color-white) 30%); The default color space should match the default used elsewhere. The syntax allows for any values as the percentages of the 2 colors. That means this minimal example is also valid: <a class="bg-sky bg-mix-white">asdf</a> background-color: color-mix(in oklab, var(--color-sky), var(--color-white)); Would a PR for this be welcome? Related: #14712 |
Beta Was this translation helpful? Give feedback.
-
You could achive with @utility text-tint-* {
color: color-mix(in srgb, --value(--color-*, [*]), white calc(--modifier(integer) * 1%));
}
@utility text-shade-* {
color: color-mix(in srgb, --value(--color-*, [*]), black calc(--modifier(integer) * 1%));
}
@utility bg-tint-* {
background-color: color-mix(
in srgb,
--value(--color-*, [*]),
white calc(--modifier(integer) * 1%)
);
}
@utility bg-shade-* {
background-color: color-mix(
in srgb,
--value(--color-*, [*]),
black calc(--modifier(integer) * 1%)
);
}
@utility border-tint-* {
border-color: color-mix(in srgb, --value(--color-*, [*]), white calc(--modifier(integer) * 1%));
}
@utility border-shade-* {
border-color: color-mix(in srgb, --value(--color-*, [*]), black calc(--modifier(integer) * 1%));
} And use them like: <a class="text-tint-base-content/10 bg-shade-[#000]/50 border-tint-primary/5">Click me</button> |
Beta Was this translation helpful? Give feedback.
-
usecase: i would love to have an easy way with tailwind to add a semitransparent overlay to an element (which has a solid background color) on hover/press/etc interactions.
something like:
currently i am adding an
::after
pseudo-element, but since tailwind v4 has added support for csscolor-mix()
i was wondering if the team has any plans to add dedicated color-mix utilities, which would make usecases like the above a bit easier?thanks!
Beta Was this translation helpful? Give feedback.
All reactions