Is it feasible to create drop shadows for SVG elements using CSS3? Something like:
box-shadow: -5px -5px 5px #888; -webkit-box-shadow: -5px -5px 5px #888;
Discussions on creating shadows using filter effects were encountered. Is there an example that only uses CSS? Below is a functional code where the cursor style is applied appropriately but no shadow effect is present. How can the shadow effect be achieved with minimal code?
svg .shadow { cursor:crosshair; -moz-box-shadow: -5px -5px 5px #888; -webkit-box-shadow: -5px -5px 5px #888; box-shadow: -5px -5px 5px #888; }
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" viewBox="0 0 120 70"> <rect class="shadow" x="10" y="10" width="100" height="50" fill="#c66" /> </svg>
Employ the CSS 'filter' attribute.
Compatible with webkit browsers, Firefox 34 , and Edge.
A polyfill is available to support FF < 34 and IE6 .
Implementation:
.shadow { -webkit-filter: drop-shadow( 3px 3px 2px rgba(0, 0, 0, .7)); filter: drop-shadow( 3px 3px 2px rgba(0, 0, 0, .7)); }
The above is the detailed content of How to Add Drop Shadows to SVGs Using Only CSS?. For more information, please follow other related articles on the PHP Chinese website!