Skip to content

Instantly share code, notes, and snippets.

@joekukish
Created August 12, 2014 18:48
Show Gist options
  • Save joekukish/40a90496372091707d15 to your computer and use it in GitHub Desktop.
Save joekukish/40a90496372091707d15 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