Skip to content

Instantly share code, notes, and snippets.

@Rob-ot
Created August 20, 2012 01:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rob-ot/3399053 to your computer and use it in GitHub Desktop.
Save Rob-ot/3399053 to your computer and use it in GitHub Desktop.
Detect which prefixed css calc to use via javascript
// public domain, use it for whatever
// returns "calc", "-moz-calc", etc
// (no -ms because they already support it non-prefixed)
function prefixedCalc () {
var prefixes = ["","-webkit-","-moz-","-o-"], el
for (var i = 0; i < prefixes.length; i++) {
el = document.createElement('div')
el.style.cssText = "width:" + prefixes[i] + "calc(9px)"
if (el.style.length) return prefixes[i] + "calc"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment