Skip to content

Instantly share code, notes, and snippets.

@xjeeh
Last active March 7, 2023 04:01
Show Gist options
  • Save xjeeh/529075192e861c3f290634fa590a6deb to your computer and use it in GitHub Desktop.
Save xjeeh/529075192e861c3f290634fa590a6deb to your computer and use it in GitHub Desktop.
Styled Component Media Query
import styled from "styled-components";
import media from "./media";
export const TitleContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
padding: 3rem;
${media.desktop`
height: 245px;
padding: 3rem 6rem;
`};
${media.widescreen`
padding: 3rem 6rem;
height: 345px;
`};
`;
import { css } from "styled-components";
const breakpoints = {
uhd: 1980,
widescreen: 1366,
desktop: 1024,
tablet: 768,
};
export const media = Object.keys(breakpoints).reduce((acc: { [key: string]: (...args: any) => any }, label) => {
acc[label] = (...args) => css`
@media (min-width: ${breakpoints[label as keyof typeof breakpoints]}px) {
${css(...args as [any])};
}
`;
return acc;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment