Edit The below is useful for other reasons, but in fact, I don't think it helps with the OP's problem of knowing whether to use the WebKit or Firefox symtax! (Doh) It helps with knowing whether the gradients can be used at all.
Edit again But! Looking at the Modernizr source shows us how to do it with a feature test (they're clever, those folks). You can probably figure it out by looking at the source yourself, but here's a quickly hacked-together example:
function testGradientSyntax() {
var element;
element = document.createElement("testsyntax");
element.style.cssText =
"background: -webkit-gradient(radial, 45 45, 10, 52 50, 30, from(#A7D30C), to(rgba(1,159,98,0)), color-stop(90%, #019F62))";
if (element.style.background.indexOf("-webkit") >= 0) {
// It's WebKit syntax
log("This supports WebKit syntax");
}
else {
// It's not WebKit syntax
log("This doesn't support WebKit syntax");
}
}
You might want to use Modernizr for this. It detects the relevant syntax and provides a way for you to use a single CSS file with both syntaxes.
Sample gradient code from the docs:
button.glossy {
background: #ccc url(gloss.png) 50% 50% repeat-x;
}
.cssgradients button.glossy {
background: #ccc -webkit-gradient(linear, left top, left bottom,
from(rgba(255,255,255, .4)),
color-stop(0.5, rgba(255,255,255, .7)),
color-stop(0.5, rgba(0,0,0, .2)),
to(rgba(0,0,0, .1)));
}
.cssgradients button.glossy:hover {
background-color: #fff;
}
(Edit In the above, I've removed a line from the end of the .cssgradients button.glossy
rule that looked to me like an error in the docs.)
See that .cssgradients
class? When you run Modernizr, it detects whether that's the relevant syntax and if so adds the class to your html
element, which turns on the descendant selector .cssgradients button.glossy
so that rule gets applied.
This is, sadly, all dependent on the browser having Javascript enabled.