How to create svg drop shadow?
I'm using a bunch of tutorials to try and get the svg shadow from me, but nothing seems to work!
Here's my fiddle: https://jsfiddle.net/5nfdovg5/
This is what I did:
- Created a gradient fill called "Gradient-1" . This one works :
- When I add a shadow filter (called "dropshadow" ) it only shows the shadow , and none of the circle that should be on top .. just a black blurred circle:
- The desired effect I need is here:
Any ideas on what I am doing wrong?
Here's the complete markup:
<svg width="200" height="200">
<defs>
<linearGradient id="Gradient-1" x1="20%" y1="30%" x2="40%" y2="80%">
<stop offset="0%" stop-color="#B8D0DE"></stop>
<stop offset="100%" stop-color="#73A2BD"></stop>
</linearGradient>
<filter id="dropshadow" xmlns="http://www.w3.org/2000/svg" height="130%">
<feGaussianBlur in="SourceAlpha" stdDeviation="3">
<feOffset dx="2" dy="2" result="offsetblur">
<feComponentTransfer>
<feFuncA type="linear" slope="0.2"></feFuncA>
</feComponentTransfer>
<feMerge>
<feMergeNode>
<feMergeNode in="SourceGraphic"></feMergeNode>
</feMergeNode>
</feMerge>
</feOffset>
</feGaussianBlur>
</filter>
</defs>
<circle cx="125" cy="125" r="25" filter="url(#dropshadow)" fill="url(#Gradient-1)"></circle>
</svg>
+3
source to share
1 answer
You seem to have nested feFilter elements, which is not the shadow code of the example you referenced in the question. Unnesting does the job as expected.
<svg width="200" height="200">
<defs>
<linearGradient id="Gradient-1" x1="20%" y1="30%" x2="40%" y2="80%">
<stop offset="0%" stop-color="#B8D0DE"></stop>
<stop offset="100%" stop-color="#73A2BD"></stop>
</linearGradient>
<filter id="dropshadow" xmlns="http://www.w3.org/2000/svg" height="130%" width="130%">
<feGaussianBlur in="SourceAlpha" stdDeviation="3"/>
<feOffset dx="2" dy="2" result="offsetblur"/>
<feComponentTransfer>
<feFuncA type="linear" slope="0.2"></feFuncA>
</feComponentTransfer>
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic"></feMergeNode>
</feMerge>
</filter>
</defs>
<circle cx="125" cy="125" r="25" filter="url(#dropshadow)" fill="url(#Gradient-1)"></circle>
</svg>
+4
source to share