@media styles are applied in the wrong order
See original GitHub issueCurrent behavior:
When using the ‘@media…’ selector, the styles are always applied after non-media styles, regardless of their order in the styles array.
To reproduce:
Here’s a simple example:
<div css={[
{ '@media screen': { color: 'blue' } },
{ color: 'red' }
]}>Text</div>
I would expect the text to be red, but it comes out blue!
Here’s a live example: https://codesandbox.io/s/emotion-issue-template-l9u7q?file=/src/index.js
Expected behavior:
I’d expect media selectors to be applied based on their order in the array instead of always being applied to the end of the list.
Here’s the equivalent example written with plain css to show what it should work like: https://jsfiddle.net/boe1k3zt/1/
Environment information:
react
version: 16.13.1emotion
version: 10.0.28
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Media query problems wrong order? - Stack Overflow
I have like 16 media queries or something and i noticed that if i put every media query portrait 1 different color some...
Read more >CSS3 Media Queries: Simple Gotchas & Easy Fixes
When a media query is true, the corresponding style rules are applied, following the normal cascading rules. More than one media query can...
Read more >media - CSS: Cascading Style Sheets - MDN Web Docs
The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media...
Read more >Wrong order of CSS styles | WordPress.org
This will only fix that particular problem. Due to the different order of CSS file inclusion, other styles might not be applied as...
Read more >Media Queries - Amazon Kindle Direct Publishing
Since CSS is applied in the order that it appears, code that targets multiple devices (such as the device-aspect-ratio code that targets all...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @Andarist,
Just to reiterate on the discussion we have here This strategy is problematic for component libraries that uses
emotion
(bigger of them being MUI),because of this behaviour there is no way for users to predictably overwrite the component style.
Take for example this component:
LibButton.tsx
The end user has no easy way to overwrite the button width using @emotion. If he writes:
The button will only take a width of
600px
on small screens.Anyway, thanks for all your work.
Closing this because it’s not something that we plan on changing - the current strategy has been proven rather successful given this is the only created issue about this behavior.