Replies: 1 comment
-
To support negative modifiers (like SolutionHere's how to handle all combinations of positive and negative values with modifiers: @utility xy-* {
--x: --value(--anim-translate-*, [*]);
--x: calc(--value(number) / 4 * 1rem);
--y: --modifier(--anim-translate-*, [*]);
--y: calc(--modifier(number) / 4 * 1rem);
translate: var(--x) var(--y, var(--x));
}
/* Positive value, negative modifier: xy-4/-8 */
@utility xy-*/-* {
--x: --value(--anim-translate-*, [*]);
--x: calc(--value(number) / 4 * 1rem);
/* Modifier becomes negative */
--y: calc(--modifier(--anim-translate-*, [*]) * -1);
--y: calc(--modifier(number) / 4 * -1rem);
translate: var(--x) var(--y, var(--x));
}
/* Negative value, positive modifier: -xy-4/8 */
@utility -xy-* {
--x: calc(--value(--anim-translate-*, [*]) * -1);
--x: calc(--value(number) / 4 * -1rem);
--y: --modifier(--anim-translate-*, [*]);
--y: calc(--modifier(number) / 4 * 1rem);
translate: var(--x) var(--y, var(--x));
}
/* Negative value, negative modifier: -xy-4/-8 */
@utility -xy-*/-* {
--x: calc(--value(--anim-translate-*, [*]) * -1);
--x: calc(--value(number) / 4 * -1rem);
--y: calc(--modifier(--anim-translate-*, [*]) * -1);
--y: calc(--modifier(number) / 4 * -1rem);
translate: var(--x) var(--y, var(--x));
} Usage Examples
Explanation
Alternative ApproachIf you prefer a more concise solution and Tailwind v4 supports arbitrary values with negative signs, you can use:
However, the explicit utility approach above provides better autocomplete support and is more predictable. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This
@utility
accepts positive values and positive modifiersAnd this one accepts negative values
What about negative modifiers?
Beta Was this translation helpful? Give feedback.
All reactions