How to Create a Range-Based Utility in Tailwind 4.0? #17275
-
Hello everyone, I'm trying to create a range utility in Tailwind 4.0. The idea is to scale a value between a given minimum and maximum based on the viewport width. For example, if I set a minimum of 20 and a maximum of 100, and define viewport limits of 1920px (max) and 375px (min), the value should scale from 100 to 20 as the screen width shrinks from 1920px to 375px. At 1920px, the value should be exactly 100, and at 375px, exactly 20. Example usage:
I managed to create a sample setup using tailwind.config.js, but what I’m really curious about is whether this can be achieved purely with CSS in Tailwind 4.0, without needing to extend the config file. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Here’s the tailwind.config.js example I mentioned:
|
Beta Was this translation helpful? Give feedback.
-
I don't think you can have all the parameters in one class name, you'd need to split it up and use CSS variables. You can at have at least two parameters per class; one that is the value and the other that is the modifier. I think it makes sense to have the modifier be the viewports, since that is optional. |
Beta Was this translation helpful? Give feedback.
I don't think you can have all the parameters in one class name, you'd need to split it up and use CSS variables. You can at have at least two parameters per class; one that is the value and the other that is the modifier. I think it makes sense to have the modifier be the viewports, since that is optional.
https://play.tailwindcss.com/XLhwOyIkjO?file=css