Issue on adding Box Shadow to SVG by CSS

Suffii picture Suffii · Mar 21, 2014 · Viewed 7.1k times · Source

can you please take a look at this demo and let me know how I can add box shadow to svg using CSS?

I already tried these

.kiwi {
  fill: #94d31b; 
  box-shadow: 10px 10px 5px #888888;
  -webkit-filter: drop-shadow( -5px -5px 5px #000 );
  filter: drop-shadow( -5px -5px 5px #000 ); 
  -webkit-svg-shadow: 0 0 7px #53BE12;
}

but they didn't' add any shadow to the SVG

Answer

Pete picture Pete · Mar 21, 2014

You can add something like the following to your svg:

<filter id="drop-shadow">
  <feGaussianBlur in="SourceAlpha" stdDeviation="2.2"/>
  <feOffset dx="1" dy="4" result="offsetblur"/>
  <feFlood flood-color="rgba(0,0,0,0.3)"/>
  <feComposite in2="offsetblur" operator="in"/>
  <feMerge>
    <feMergeNode/>
    <feMergeNode in="SourceGraphic"/>
  </feMerge>
</filter>

and then use the following styles:

.kiwi {
  fill: #94d31b; 
  -webkit-filter: drop-shadow(0 1px 10px rgba(113,158,206,0.8));
  filter: url(#drop-shadow);
}

Example