How to use styled-jsx with responsive design (media queries)?
See original GitHub issueAre there any best practices for using styled-jsx
with responsive design (media queries)?
I’m experimenting with react-responsive but it doesn’t seem to accept <style jsx>
inside like:
<MediaQuery query='(max-width: 600px)'>
<style jsx>{`
.my-element {
background-color: tomato;
}
`}</style>
</MediaQuery>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:18
Top Results From Across the Web
How to use media queries with styled components
Non responsive website Click the button below to Edit on CodeSandbox Edit Styled components media queries (before).
Read more >Style JSX is not working properly with @media-query in NextJS
I am using <style jsx> in Next JS to style my components. When that code is compiled @media query isn't executed successfully.
Read more >Media queries with styled components - Mario Kandut
1. Define breakpoints · 2. Define devices · 3. Apply media query in styled-component.
Read more >React inline styles and media queries using a ... - Medium
I'm a big fan of React inline styles. Co-locating styles with the component and using javascript to define them fits my programmer brain ......
Read more >How To Use Media Queries in React - Upmostly
Media queries are used in responsive design. They are used to apply different CSS rules to different types of devices, most commonly screen...
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 Free
Top 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
@joncursi that’s correct. You’d need do add an event listener and keep a boolean in the state:
which you can use like this
I didn’t test or try the code above but it should work. I believe that https://www.npmjs.com/package/react-media is implemented in a similar way
Anyway this is going out of topic 😃 I think that option 1) and 2) from my comment https://github.com/zeit/styled-jsx/issues/254#issuecomment-313841098 are a good way to go.
If you need now you can also use dynamic styles eg.