Add ability to add max breakpoint (not just min breakpoints) to theme, e.g. --max-breakpoint-* #18916
Replies: 6 comments 2 replies
-
Okay, I added a pull request for this feature! Thanks!!!!!!! |
Beta Was this translation helpful? Give feedback.
-
You can currently do something like this: @custom-variant tablet (@media (max-width: 1001px));
@custom-variant phone (@media (max-width: 501px));
It's important that in this case you declare the variants in descending order, as this ensures the utilities will be applied in the correct order. Here’s a bad example: @custom-variant phone (@media (max-width: 501px)); /* not working */
@custom-variant tablet (@media (max-width: 1001px));
Just for fun, can declare something, like this: @custom-variant example (@media (min-width: 1000px) and (max-width: 2000px)); /* activated between 1000px and 2000px */ |
Beta Was this translation helpful? Give feedback.
-
If I want to stick with your example - and I don't want to shorten it to one line - then I need to start with @custom-variant tablet {
@media (width <= 1001px) {
@slot;
}
}
@custom-variant phone {
@media (width <= 501px) {
@slot;
}
}
Here are some other |
Beta Was this translation helpful? Give feedback.
-
Or yeah just use
@theme {
--breakpoint-tablet: 1000px;
--breakpoint-phone: 500px;
} |
Beta Was this translation helpful? Give feedback.
-
@rozsazoltan Amazing--so I think I must be having some super odd VIte/TW4 thing going on or something... I just started with a default vite/tw4 install... I spent hours messing with this yesterday, and yes, for sure I started with your suggestion, e.g. @custom-variant tablet (@media (max-width: 1001px));
@custom-variant phone (@media (max-width: 501px)); Here is some simple, test html: <div class="phone:bg-sky-500 tablet:bg-amber-500 bg-emerald-300">
Hello World
<div class="flex p-3 bg-yellow-300 flex-row phone:flex-col">
<div class="h-5 bg-red-400 w-full"></div>
<div class="h-5 bg-blue-400 w-full"></div>
</div>
</div> So, here's what I get in TW playground (works perfectly!!! OMG): And here is what I get locally, in VIte/TW4: ![]() Crazy, right? Here is my code and config: ![]() ![]() In my local VIte, the code shows up at the bottom of the cascade and it therefore not used: In Tailwind Playground, it shows up at the top of the stack, and is therefore applied: So I guess this is officially a TW/VIte bug??? Let me build it to see if it's just a preview issue... Yeah, same thing in Okay, so yeah the layer utilities are getting the order correct: But there is an "upper" css that is overriding those layer utilities: I'll do some more digging to see if I can sort out the layer utilities thing... |
Beta Was this translation helpful? Give feedback.
-
All good, no need to add this...
@import "tailwindcss";
@source "./**/*.html";
@source "./src/**/*.{js,ts,jsx,tsx}";
@custom-variant tablet (@media (max-width: 1001px));
@custom-variant phone (@media (max-width: 501px)); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This is critical and am happy to write this code.
In TW3, you could just add:
to your theme and you were all set.
But in TW4, this is literally impossible to do. This code can no longer be made to work:
because of media query changes.
In English, the tw code above says "Make this div a
flex-row
, unless it's a phone, in which case, make it aflex-col
"TW3 (old way):
TW4 (new way):
Neither of these work:
Proposal:
Add a
--max-breakpoint-*
theme variable, which would work exactly like--breakpoint-*
, but using (max) instead of (min).That way, for folks like myself who design desktop-first, then tablet, then mobile, they can use their old TW3 code, instead of having to use the awkward
@max-phone:flex-col
syntax.Sidebar: I know this is "set in stone", but let's be honest. Mobile-first sounds cool, but logically is very mentally taxing.
Because you have to think--"Ah, this screen is now BIGGER than
sm
, so I have to add ansm
tag to account for a larger screen". Very confusing. Like literally, every time you look at responsive TW code, you invert your mental model.sm
== big, etc.As opposed to a
phone
breakpoint, you design your regular website using normal classes, e.g.flex flex-col
, etc., then when you need to squeeze it onto a phone, you just addphone:
tags to make it look pretty.PS--I love tailwind!!!! Would love to contribute.,
Beta Was this translation helpful? Give feedback.
All reactions