Recently I discussed the drop-shadow filter, which is newly supported in Webkit. Firefox users saw the same effect in the article, even though the browser doesn’t yet support CSS3 filters.
That’s due to the fact that Firefox supports the older SVG version of the filter, from which the CSS3 version is derived. In this article I’m going to show you how to write the effect for all browsers*, so you can achieve the benefits of a true, dynamic drop shadow for all elements.
Webkit
The CSS3 Webkit version first, as a refresher:
The syntax is very straightforward: the values for the filter represent, in order, horizontal offset, vertical offset, blur and the color of the shadow (given as an rgba value to create a realistic shadow against any background).
Firefox
Now the SVG version. You can either save this as a separate file (shadow.svg) or embed it on a web page. The code is as follows:
The SVG syntax is considerably more complex, and I’m not going to explain all of it here. The good news is that you only need to alter four values: stdDeviation is the amount of blur; dx is the horizontal offset and dy the vertical, with flood-color being the color of the shadow.
IE
Finally, the equivalent for Internet Explorer:
You’ll find that the visual quality is not nearly as good in IE – and you do have to do some re-jiggering and testing to translate the CSS3/SVG values into legacy DX filters – but the dropshadow will appear at least appear in Internet Explorer.
Bringing It All Together
I’d suggest combining all these approaches as a class, as you’d usually want to apply the effect to more than one element on the same page… and naturally, you’d want all of the shadows on the page to fall in the same direction, to ensure a consistent visual appearance:
(If you embedded the SVG code directly on the page, you’d use just the id value: note that it matches the id on the SVG code sample).
That’s it! You can now apply the class to a transparent PNG or any other element to gain a true drop-shadow effect across modern browsers.
*Opera is the exception here: it neither supports SVG filters on external content nor the native CSS3 filters, at least as of this writing.
Pro CSS3 Animation, Apress, 2013
Massive Head Canon
The New Defaults
CSSslidy