Home > Web Front-end > CSS Tutorial > Can CSS3 Apply Drop Shadows to SVG Elements?

Can CSS3 Apply Drop Shadows to SVG Elements?

Patricia Arquette
Release: 2025-01-02 18:32:38
Original
429 people have browsed it

Can CSS3 Apply Drop Shadows to SVG Elements?

CSS3 SVG Drop Shadow

Is it possible to apply drop shadow to SVG using CSS3?

Yes, using the CSS filter property, which is supported by modern browsers like webkit browsers, Firefox 34 , and Edge.

Syntax

filter: drop-shadow(horizontal-offset vertical-offset blur-radius color);
Copy after login

Example

.shadow {
  filter: drop-shadow(3px 3px 2px rgba(0, 0, 0, .7));
}
Copy after login

You can also use this in SVG elements:

<svg>
  <rect class="shadow" x="10" y="10" width="200" height="100" fill="#bada55" />
</svg>
Copy after login

Polyfill for Legacy Browsers

For browsers like Firefox < 34, IE6 , you can use this polyfill:

// Usage:
// $(element).cssShadow({horizontal-offset, vertical-offset, blur-radius, color});

$.fn.cssShadow = function(options) {
  // CSS syntax to include the units of the values
  var css = "-webkit-filter: drop-shadow("
    + options.horizontalOffset + "px "
    + options.verticalOffset + "px "
    + options.blurRadius + "px "
    + options.color
    + ");";

  // Applying the css
  return this.css({
    'filter': css,
    '-webkit-filter': css
  });
};
Copy after login

The above is the detailed content of Can CSS3 Apply Drop Shadows to SVG Elements?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template