Skip to content

Instantly share code, notes, and snippets.

@jeroenransijn
Last active February 20, 2020 19:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenransijn/27104db330db2120d2e831b515f3cd3c to your computer and use it in GitHub Desktop.
Save jeroenransijn/27104db330db2120d2e831b515f3cd3c to your computer and use it in GitHub Desktop.
Hacking CSS rem into a responsive unit
/**
* Responsive rem hack
* ---
* Makes the `rem` unit behave like a dynamic value based on the viewport, with a max width.
* This makes it easy to apply dynamic values to margin and paddings.
* warning, `rem` becomes useless for font-sizes.
*
* Usage:
*
* .vertical-spacing {
* margin-top: 10rem;
* margin-bottom: 10rem;
* }
*/
html {
font-size: 16px;
/* for any viewport size smaller than 1000px map rem to vw (viewport width) */
@media (max-width: 1000px) {
font-size: 1.6vw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment