Last active
February 20, 2020 19:01
-
-
Save jeroenransijn/27104db330db2120d2e831b515f3cd3c to your computer and use it in GitHub Desktop.
Hacking CSS rem into a responsive unit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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