Skip to content

Instantly share code, notes, and snippets.

@lunelson
Last active September 18, 2015 08:26
Show Gist options
  • Select an option

  • Save lunelson/801f044944739b8c8df6 to your computer and use it in GitHub Desktop.

Select an option

Save lunelson/801f044944739b8c8df6 to your computer and use it in GitHub Desktop.
RESET mixin
// ----
// Sass (v3.3.14)
// Compass (v1.0.3)
// ----
@mixin width($span: 1 1, $options: ()) {
@include width-helper(map-merge((span: $span), $options)...);
}
@mixin width-helper($span: 1 1, $right: null, $left: null, $cycle: null, $out: null) {
$n: nth($span, 1); $d: nth($span, 2);
width: $n / $d * 100%;
@if $right { margin-right: nth($right, 1) / if(length($right) > 1, nth($right, 2), $d) * 100%; }
@if $left { margin-left: nth($left, 1) / if(length($left) > 1, nth($left, 2), $d) * 100%; }
@if $cycle { &:nth-child(#{$cycle}n+1) { clear: left; } }
@else if $out { position: absolute; #{opposite($out)}: 100%; }
}
.test {
color: blue;
@include width(1 3, (right: 1 2, left: 2 5));
}
.test2 {
color: blue;
@include width(1 1, (out: right));
}
.test {
color: blue;
width: 33.33333%;
margin-right: 50%;
margin-left: 40%;
}
.test2 {
color: blue;
width: 100%;
position: absolute;
opposite(right): 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment