Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a drop shadow to an SVG path element?

I've been attempting to apply a drop shadow to my SVG Path. I googled across the filter option which when applied to path by applying: -webkit-filter: drop-shadow( -5px -5px 10px #000 ); which didn't seem to get applied.

Here's a fiddle with my SVG path demonstrating the problem

like image 382
Louis93 Avatar asked Jul 15 '15 14:07

Louis93


People also ask

Can you add drop shadow to SVG?

The SVG <feDropShadow> filter primitive creates a drop shadow of the input image. It can only be used inside a <filter> element. Note: The drop shadow color and opacity can be changed by using the flood-color and flood-opacity presentation attributes.

How can you add a shadow to your element?

In CSS, shadows on the boxes of elements are created using the box-shadow property (if you want to add a shadow to the text itself, you need text-shadow ). The box-shadow property takes a number of values: The offset on the x-axis. The offset on the y-axis.

Which property is used to create a drop shadow?

We can add a drop shadow to any HTML element using the CSS property box-shadow .

Which CSS property is used to add shadow to an element?

The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.


1 Answers

Within your JSFiddle, I deleted your CSS and added a filter definition. It seems to work:

<svg width="100%" height="300px">
<defs>
       <filter id="filter1" x="0" y="0">
           <feOffset result="offOut" in="SourceAlpha" dx="-5" dy="-5" />
           <feGaussianBlur result="blurOut" in="offOut" stdDeviation="3" />
           <feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
    </filter>
</defs>
<path stroke-linejoin="round" stroke-linecap="round" stroke="red" stroke-opacity="1" stroke-width="5" fill="none" class="leaflet-clickable" d="M1063 458L1055 428L1034 433L1030 421L1017 423L911 452L895 455L885 441L859 424L809 410L788 394L774 377L744 309L730 313L727 304L669 319L599 341L596 331L491 364L488 357L498 343L490 343L450 352L417 256L371 270L366 253L355 256L351 242L217 282L194 210L191 196L166 113L45 147L44 140L13 150" filter="url(#filter1)"></path>
</svg>

Maybe a few tweaks to the dx, dy, and stdDeviation values will get it just the way you want.

like image 108
cobaltduck Avatar answered Oct 04 '22 01:10

cobaltduck