Skip to content

Instantly share code, notes, and snippets.

@rzkhosroshahi
Last active July 25, 2017 18:18
Show Gist options
  • Save rzkhosroshahi/2db1772e19ef9956eef78a31a0a4590b to your computer and use it in GitHub Desktop.
Save rzkhosroshahi/2db1772e19ef9956eef78a31a0a4590b to your computer and use it in GitHub Desktop.
This snippet computing golden ratio field for SASS/SCSS
@function scaleMath($n) {
@if $n == 0 {@return 1;}
@if $n == 1 {@return 1.618;}
@if $n == -1 {@return 0.618;}
@if $n > 0{
@return scaleMath($n - 1) + scaleMath($n - 2);
}
@if $n < 0 {
@return scaleMath($n + 2) - scaleMath($n + 1);
}
}
// example
.container {
width: #{scaleMath(-3)}; // 0.236
}
// or
@function scaleRem($val){
@return #{scaleMath($val)}rem;
}
.container {
width: scaleRem(2); // 2.618rem
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment