Created
July 20, 2014 00:22
-
-
Save cuibonobo/42251b1eda192ad87be2 to your computer and use it in GitHub Desktop.
Use rem units in CSS as if they were pixels. Also includes a pixel fallback for older browsers.
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
| <html> | |
| <head> | |
| <title>This.</title> | |
| </head> | |
| <body> | |
| <p>This.</p> | |
| </body> | |
| </html> |
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
| // ---- | |
| // Sass (v3.3.10) | |
| // Compass (v1.0.0.alpha.20) | |
| // ---- | |
| $rootFontSize: 16px; | |
| @function calculateRem($size) { | |
| $remSize: $size / $rootFontSize; | |
| @return #{$remSize}rem; | |
| } | |
| @mixin rem($propertie, $value) { | |
| /* Fallback */ | |
| #{$propertie}: $value; | |
| #{$propertie}: calculateRem($value); | |
| } | |
| html { | |
| font-size: $rootFontSize; | |
| } | |
| p { | |
| font-size: calculateRem(32px); | |
| @include rem(width, 100px); | |
| @include rem(margin, 50px); | |
| } |
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
| html { | |
| font-size: 16px; | |
| } | |
| p { | |
| font-size: 2rem; | |
| /* Fallback */ | |
| width: 100px; | |
| width: 6.25rem; | |
| /* Fallback */ | |
| margin: 50px; | |
| margin: 3.125rem; | |
| } |
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
| <html> | |
| <head> | |
| <title>This.</title> | |
| </head> | |
| <body> | |
| <p>This.</p> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment