Responsive spacing values #10917
Replies: 1 comment 2 replies
-
You could use module.exports = {
theme: {
extend: {
spacing: {
foo: 'clamp(10px, (100vw - 500px) * 99, clamp(14px, (100vw - 1000px) * 99, 24px))',
},
},
},
}; This example would make the smallest value to be
When the viewport width is less than
When the viewport width is less than |
Beta Was this translation helpful? Give feedback.
-
Hi 👋
I have a weird (maybe not?) use case and I wanted to get everybody's opinion on how to achieve this in tailwind. I'm trying to migrate a design system into tailwind and the first thing I'm looking at is the spacing tokens.
In the design system I'm using, spacing values are "responsive". That means that
space-1
will be 10px on small devices, 14px on larger devices and 24px on large devices (I'm just making these up, but that's how it works).So I'd like to use, let's say, a margin utility like
mt-1
and have that value automatically change.Here's the idea I have in mind: I can have the spacing tokens as CSS variables and update those through media queries in a global CSS file. Then I can use the css variable in tailwind.config.js.
The issue I see with that is that I'm going to end up with tons of variables and CSS that might not always be needed. I only want to output to the page as little CSS as I can.
Furthermore I have another use case regarding colors where, with the solution I mentioned above, I could end up with hundreds of variable.
Is there any way to extend tailwind's config and fit my use case?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions