tailwindcss
tailwindcss copied to clipboard
Extending screens config breaks arbitrary values
What version of Tailwind CSS are you using?
v3.3.5
What build tool (or framework if it abstracts the build tool) are you using?
Vite 4
What version of Node.js are you using?
v18.0.0
What browser are you using?
Chrome, Safari, or N/A
What operating system are you using?
Windows / Linux
Reproduction URL
https://play.tailwindcss.com/fvlYPhEOPh?file=config
Describe your issue
When extending screens in tailwind configuration (using min/max or raw), it breaks arbitrary values:
// tailwind.config.js
/** @type {import('tailwindcss').Config} */
export default {
theme: {
extend: {
screens: {
'2xl': { min: '1536px' }, // fixed range breaks arbitrary values
tall: { raw: '(min-height: 800px)' }, // raw breaks arbitrary values
},
},
},
plugins: [],
}
Makes this don't work:
<div class="min-[600px]:text-red-400 max-[600px]:text-sky-300">
Test arbitray screen values
</div>
Hi! Thank you for the report. This is a known limitation, see https://github.com/tailwindlabs/tailwindcss/pull/9558#user-content-restrictions for details.
Yeah this is currently by design because we can't properly sort media queries and get the correct precedence behavior when applying the classes in your HTML when they are mixed like this, but I'm going to leave this open for a bit as a reminder to look into it again and sort of remember where the challenges were and see if we can't do something a bit better.
One idea is to group the media queries by "type" for sorting purposes and keep the min/max ones grouped with the regular min-width-based media queries for example. Could do the same thing for the mixed unit problem possibly — you'd get strange results but if they are deterministic perhaps that's all we need.
@adamwathan I’m noticing that this also breaks when targeting breakpoints, not just for arbitrary values. It might be worth noting this alongside the custom media queries documentation.
Am I right in thinking that it’s not currently possible to do height-based (or other) media queries using Tailwind as well as being able to use either arbitrary width breakpoints and/or breakpoint targeting?
Indeed as per #9558, any non-"simple" breakpoints will stop any max-* or min-* variants from working, which would in turn make targeting breakpoints not possible (in the form in the documentation).
It's possible to do height-based media queries using Tailwind as well as being able to use either arbitrary width breakpoints and/or breakpoint targeting. You could:
- Register height-based media queries in a Tailwind plugin.
- Use arbitrary variants like
[@media(min-height:200px)]:text-red-500.
@wongjn Big thank you for the guidance 🙏🏻