I can get media queries to work properly inside a regular styled-components
component however when I attempted to use it in a keyframe
(via import from styled-components
) it does not seem to work at all.
Attempting to get a div to animate to a specific position, but have that end position change when the window is < 800px, I've attempted this:
import styled, { keyframes } from 'styled-components';
// ... further down ...
const slideAnim = keyframes`
100% {
top: 20px;
left: 30px;
}
@media (max-width: 800px) {
top: 70px;
left: 50px;
}
`;
I have also tried putting the media query in the 100%
block:
const slideAnim = keyframes`
100% {
top: 20px;
left: 30px;
@media (max-width: 800px) {
top: 70px;
left: 50px;
}
}
`;
I made a helpful interactive demonstration of what I am trying to achieve (problem code is at line 24): https://codesandbox.io/embed/fragrant-star-m71ct
Feel free to change the breakpoint
variable from 800 if you need to.
Any help is appreciated!