-
-
Save malei0311/81296f9b52ec805557b111d41f8332f0 to your computer and use it in GitHub Desktop.
rem() mixin for Less CSS
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
| /* --------------------------------------------------------------------------- | |
| Toolkit: Rem | |
| ============ | |
| .rem() takes a @property, and @list of values (in px or unitless) and | |
| converts to rem. | |
| e.g., | |
| .selector { | |
| .rem( margin, 20 auto eggs 666% ); | |
| .rem( font-size, 12 ); | |
| } | |
| Makes life a little easier when working from designs specced in pixels. | |
| --------------------------------------------------------------------------- */ | |
| .rem( @property, @list, @base: 16 ) { | |
| @n: length(@list); | |
| // Only convert numbers that are not percentages or 0; | |
| ._merge( @px ) when ( isnumber(@px) ) and not ( ispercentage(@px) ) and not ( @px = 0 ) { | |
| @rem: ( @px / @base ); | |
| @{property}+_: unit(@rem, rem); | |
| } | |
| ._merge( @px ) when ( default() ) { | |
| @{property}+_: @px; | |
| } | |
| ._loop( @n ) when ( @n > 0 ) { | |
| ._loop((@n - 1)); | |
| @val: extract(@list, @n); | |
| ._merge( @val ); // merges values onto @property with space character. | |
| } | |
| ._loop( @n ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment