Skip to content

Instantly share code, notes, and snippets.

@HelgaZhizhka
Forked from joekukish/calc-mixin.styl
Created March 15, 2016 11:02
Show Gist options
  • Save HelgaZhizhka/d485a760def0fcca6c20 to your computer and use it in GitHub Desktop.
Save HelgaZhizhka/d485a760def0fcca6c20 to your computer and use it in GitHub Desktop.
Stylus `calc()` mixin
// Adds the vendor prefixes for calc.
//
// Usage:
// width: calc('30% - 10px');
// If variables are needed they need to be specified this way.
// width: calc('40% \- %s' % (10px));
calc() {
// vendors to be used by this function
calc-vendors = webkit moz;
if current-property {
// arguments get unquoted
arguments = unquote(arguments);
// iterates over the vendor prefixes
for prefix in calc-vendors {
add-property(current-property[0], s('-%s-calc(%s)', prefix, arguments));
}
s('calc(%s)', arguments);
} else {
error('calc() must be used within a property');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment