I want a piece of dark text on dark background to have a white glow outside of it. Although the default drop shadow filter in CSS (like filter: drop-shadow(2px 2px 2px black)
) officially should support a 'spread-radius' fourth attribute, support for this attribute is basically non-existent. Without this extra spread, the drop shadow will not be big enough to allow the text to be read.
So, I decided to define my own filter in an SVG tag, including a dilation operation to implement the extra spread, and apply that to the text instead. This filter works fine in Chrome, but causes the text to become entirely invisible in Firefox (both tested under Ubuntu 14.04). According to caniuse.com (usually very reliable, I've found), Firefox should support the filter perfectly fine.
The HTML code with SVG filter:
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<filter id="my-drop-shadow" x="0" y="0" width="200%" height="200%">
<feColorMatrix type="matrix" values=
"0 0 0 0 1
0 0 0 0 1
0 0 0 0 1
0 0 0 1 0"/>
<feMorphology operator="dilate" radius="2" />
<feGaussianBlur stdDeviation="2" in="coloredOut" result="coloredBlur"/>
<feMerge>
<feMergeNode in="coloredBlur"/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
</defs>
</svg>
<p>Hello there.</p>
The CSS:
body {
color: #000; background: #002;
font-family: serif; font-size: 30px;
font-weight: bold;
}
p {
-webkit-filter: url(#my-drop-shadow);
filter: url(#my-drop-shadow);
}
Result on Chrome (version 46.0.2490.80 (64-bit)):
Result on Firefox (version 42.0):
I've put the code above in a working CodePen (edit: note that I've now updated the CodePen to reflect @RobertLongson's answer and it works; see below though for why this was not the full answer).
Any ideas? Typo I haven't spotted in my SVG code?
There's an input called coloredOut but no output called coloredOut so the filter chain fails. Removing the in="coloredOut" attribute seems to fix that. You might want to raise a Chrome bug that it's not enforcing valid filter chains.
In addition the SVG pushes the text down so you can't see it in the codepen. Adding width="0" height="0" to the <svg>
element fixes that issue.