Skip to content

Instantly share code, notes, and snippets.

@azamatsmith
Last active September 7, 2022 17:07
Show Gist options
  • Save azamatsmith/a56fb3f8cd3657db7a6af6ce1f8ea591 to your computer and use it in GitHub Desktop.
Save azamatsmith/a56fb3f8cd3657db7a6af6ce1f8ea591 to your computer and use it in GitHub Desktop.
Reusable media queries with Styled Components
import { css } from 'styled-components';
export const breakpoint = {
medium: '48em',
large: '64em',
};
export const media = {
// ns = not small
ns: (...args) =>
css`
@media screen and (min-width: ${breakpoint.medium}) {
${css(...args)}
}
`,
medium: (...args) =>
css`
@media screen and (min-width: ${breakpoint.medium}) and (max-width: ${breakpoint.large}) {
${css(...args)}
}
`,
large: (...args) =>
css`
@media screen and (min-width: ${breakpoint.large}) {
${css(...args)}
}
`,
};
import styled from 'styled-components';
import { media } from 'utils/mediaQuery';
const Title = styled.h1`
font-size: 24px;
${media.medium`
font-size: 30px;
`}
${media.large`
font-size: 36px;
`}
`;
export default Title;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment