Created
February 3, 2013 16:00
-
-
Save lunelson/4702284 to your computer and use it in GitHub Desktop.
GCD and Reduce to chain extension of column width classes
This file contains 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.2.5 | |
@function gcd($n,$d) { | |
$numerator: if($n < $d,$d,$n); | |
$denominator: if($n < $d,$n,$d); | |
$remainder: $numerator; | |
$last_remainder: $numerator; | |
@while $remainder != 0 { | |
$last_remainder: $remainder; | |
$remainder: $denominator % $numerator; | |
$denominator: $numerator; | |
$numerator: $remainder; | |
} | |
@if $last_remainder != 0 { | |
@return $last_remainder; | |
} | |
} | |
@function reduce($n,$d) { | |
$gcd: gcd($n,$d); | |
@return ($n/$gcd,$d/$gcd) | |
} | |
$columns: 24; | |
@for $d from 1 through $columns { | |
@for $n from 1 through $d { | |
$ratio: reduce($n,$d); | |
$x: nth($ratio,1); $y: nth($ratio,2); | |
%span-#{$n}-#{$d} { | |
@if $x < $n { | |
@extend %span-#{$x}-#{$y}; | |
} @else { | |
width: $n/$d*100%; | |
} | |
} | |
} | |
} | |
.test { | |
@extend %span-3-4; | |
} | |
.test2 { | |
@extend %span-9-12; | |
} |
This file contains 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
.test2, .test { | |
width: 75%; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment