-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new min
and max
variants
#9558
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Technically each test isn’t 100% sorted right in isolation because prettier decisions are basically project-wide. This is close enough though.
Closed
27 tasks
Hi Dear, I configure the screens property, after configuring, the Arbitrary values such as Thanks for your help.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces three new pieces of functionality related to screen variants.
New Features
Sort screens by value (instead of config order)
Currently, screens are sorted by the order they appear in your
tailwind.config.js
file. This is great until you want to add your ownxs
variant throughextends
. Right now if you do that Tailwind will place thexs
variant at the end of your screens list and at the end of your CSS, causingxs
to incorrectly take precedence over higher screen variants / sizes.To work around this you must duplicate your screens list and place
xs
at the beginning:Now, with this change, you can use
extends
and it will work as expected:With the above config and this HTML:
This is now the output:
Adds a
max-*
variant formax-width
screen sizesCurrently, it is possible to define your own
max-width
screen sizes in the config by adding more screens in the appropriate order:But this solution has some drawbacks:
max-width
screens MUST appear in descending order. Not doing so would causemax-2xl
to override the all the othermax-width
screens since screens that are 480px wide, 768px wide, etc… are all also at most 1536px wide.extends
to add them because they should be placed beforemin-width
screens for optimal behavior.This new feature addresses all of these shortcomings for simple,
min-width
-based screen configs.Better yet, you do not have to add more screens yourself — they're automatically supported!
Now, without modifying your screens at all you'll be able to write this:
And this is the output:
Further, you can combine standard screen variants and the new max variant to produce a "between" or range variant for your utility:
Which means, when the viewport is at least
640px
and less than768px
, the padding will be applied.The
max-*
variant also supports arbitrary valuesAnd, because it utilizes the new
matchVariant
feature in v3.2+ themax-*
variant supports arbitrary values, not just screen names. This is great for one-off cases when it doesn't make sense to add an additional screen to your config. This means you can do things like this:And this is the output:
Adds a
min-[]
variant specifically for arbitrary valuesTailwind's screens are all already
min-width
by default. And this holds true for most projects that customize their screens config to add additional screen sizes. This means that, normally, there's no need for amin
variant.But, wait, we just added arbitrary values to the
max-*
variant. If you can do that formax-width
screen sizes it stands to reason that you'd want to do this formin-width
screen sizes as well.Introducing the
min-[]
variant!You can now do this:
And this is the output:
Even better, these are sorted in ascending order alongside other screen variants in your project's config since they are also
min-width
-based:Which produces this output:
Restrictions
Your screens, if customized, MUST be
min-width
only and string valuesTo ensure proper sorting we've made the decision to restrict the use of these features to screens that are "simple", meaning that they are
min-width
-based, and consist of only string values that use the same units.For example, these are all valid:
While these are invalid and will disable these new features:
psst if you're using custom screens in your project for landscape, portrait, or print media queries we have variants for those already!
All screens including both built-in and custom ones MUST all use the same units
For example, these are all valid:
While these are invalid and will disable all of these new features together:
All uses of
min
andmax
MUST use the same units (including built in and custom screens)To ensure proper sorting we've made the decision to restrict the use of
min
andmax
to the same units. This means you can't do any of these — across your whole project:If you want to use
rem
for yourmin
andmax
values you'll need to userem
for all of your screens as well.tl;dr
As long as your screens config is "simple" (see restrictions above):
extends
and they'll be properly sorted among your other screens.min-[]
variant that allows you to use arbitrary values withmin-width
media queries which are sorted in ascending order alongside your other screens.max-*
variant, which supports both your screens config and arbitrary values and are sorted in descending order and all of them are before your min-width screens.