Skip to content

Instantly share code, notes, and snippets.

@5509
Created March 27, 2012 15:36
Show Gist options
  • Save 5509/2217089 to your computer and use it in GitHub Desktop.
Save 5509/2217089 to your computer and use it in GitHub Desktop.
Choosing use vendor prefix or not by like hash for Sass
$use:
-webkit-, true,
-moz-, true,
-o-, true,
-ms-, false;
@mixin addPrefix($property, $value, $def: false) {
$property: unquote($property);
$value: unquote($value);
@for $i from 1 through length($use)/2 {
$n: $i * 2;
$flg: nth($use, $n);
$prfx: nth($use, $n - 1);
@if $def {
$_index: index($def, $prfx);
@if $_index {
$flg: nth($def, $_index + 1);
}
}
@if $flg {
#{$prfx + $property}: $value;
}
}
#{$property}: $value;
}
@5509
Copy link
Author

5509 commented Mar 27, 2012

// Usage
// default
@mixin background-size($value) {
@include addPrefix('background-size', $value);
}

// using with default using or not
@mixin box-shadow($value) {
$def:
-webkit-, false,
-ms-, true;
@include addPrefix('box-shadow', $value, $def);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment