I've got an SVG object that contains a linear gradient embedded directly in a document. It works fine in Chrome and Firefox, but in Safari nothing is rendered. If I create the SVG as a file and embed it using the Object tag, it works fine in Safari. Other shapes and fills work, it's just linear gradient that doesn't work. I guess I could use the object, but I'd prefer to embed the SVG directly.
I've create a demo here (works in Chrome, not Safari): http://jsfiddle.net/sjKbN/
I came across this answer which suggests setting the content type to application/xhtml+xml
, but this in itself seems to cause other problems.
Just wondering if anyone had come across any other fixes or ideas to get this working.
The accepted answer was not the solution for me.
My problem was the presence of a
<base href="/" />
tag in my index file. Simply removing it solved the problem for me.If you cannot remove it, probably some workaround already exist: found this gist but I did not tested it.
Update
Simply removing the href broke the child routing of my angular app, the proper workaround is to prepend to the linearGradient id with the page relative location. I wrapped the logic in a method like this:
Your gradient will work in Safari if you wrap a
defs
tag around it:It seems that wrapping your references in
defs
is encouraged but not obligatory according to spec. So this is a bug in Safari.About Alpha : It seems that Safari (7 at this moment) does not cover SVG color alpha channel, use stop opacity attribute. it works fine!