When manipulating a parent element with identical dimensions, SVG shadows are only clipped during the transformation

Why is the drop shadow of my SVG getting cut off when I scale or rotate its parent element? The behavior seems to change when the parent element is the same width and height as the SVG. Here's a link for reference.

scale.addEventListener("mousedown", function(){
    this.parentElement.classList.toggle("scale");
})
svg{
  fill: yellow;
  overflow: visible;
  width: 100%;
}
body > div{
  position: absolute;
  left: 50px;
  top: 50px;
}
div > div{
  display: inline-block;
  width: 150px;
  transition: 5s all;
}
div > div:nth-of-type(1){
   padding: 15px;
}
div.scale > div{
  transform: scale(0);
}
<div>
  <button id="scale">
    scale
  </button>
  <div>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 409.96 254.59">
      <defs>
        <filter filterUnits="userSpaceOnUse" id="f1">
          <feDropShadow filterUnits="userSpaceOnUse" dx="1.5" dy="0.8" stdDeviation="1"></feDropShadow>
        </filter>
        <filter filterUnits="userSpaceOnUse" id="f2">
          <feDropShadow filterUnits="userSpaceOnUse" dx="-2" dy="1.8" stdDeviation="1"></feDropShadow>
        </filter>
        <filter filterUnits="userSpaceOnUse" id="f3">
          <feDropShadow flood-opacity="0.1" stdDeviation="10" dy="-4" dx="-2" filterUnits="userSpaceOnUse"></feDropShadow>
        </filter>
      </defs>
      <g style="filter: url(#f2);">
        <g style="filter: url(#f3);">
      <path d="M167.1,52.17S209.77-28.24,301.66,10.6c0,0,59.62,23.52,56.34,96.81,0,0,55.45,16.41,51.79,79.86,0,0-.3,61.95-67.65,67.28H220.75q-72.56,0-145.12,0C29.57,254.66-2.8,215,.19,170.31c0,0,7.74-70,81.58-68.37C81.77,101.94,101.46,42.87,167.1,52.17Z" style="filter: url(#f1);"></path>
        </g>
      </g>
    </svg>                            
  </div>
  <div>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 409.96 254.59">
      <defs>
        <filter filterUnits="userSpaceOnUse" id="f1">
          <feDropShadow filterUnits="userSpaceOnUse" dx="1.5" dy="0.8" stdDeviation="1"></feDropShadow>
        </filter>
        <filter filterUnits="userSpaceOnUse" id="f2">
          <feDropShadow filterUnits="userSpaceOnUse" dx="-2" dy="1.8" stdDeviation="1"></feDropShadow>
        </filter>
        <filter filterUnits="userSpaceOnUse" id="f3">
          <feDropShadow flood-opacity="0.1" stdDeviation="10" dy="-4" dx="-2" filterUnits="userSpaceOnUse"></feDropShadow>
        </filter>
      </defs>
      <g style="filter: url(#f2);">
        <g style="filter: url(#f3);">
      <path d="M167.1,52.17S209.77-28.24,301.66,10.6c0,0,59.62,23.52,56.34,96.81,0,0,55.45,16.41,51.79,79.86,0,0-.3,61.95-67.65,67.28H220.75q-72.56,0-145.12,0C29.57,254.66-2.8,215,.19,170.31c0,0,7.74-70,81.58-68.37C81.77,101.94,101.46,42.87,167.1,52.17Z" style="filter: url(#f1);"></path>
        </g>
      </g>
    </svg>                            
  </div>
</div>  

Answer №1

One thing to note is that overflow shadows do not remain during transform transitions, so it's important to add margin/padding to your box to ensure they display correctly.

Also, you can simplify your SVG code by:

  • Avoiding the re-declaration of filters within each inline SVG fragment
  • Declaring filterUnits only in the filter element itself (not each primitive)
  • Using self-closing tags for feDropshadow (" />")
  • Removing the style and directly declaring a filter attribute

<div>
  <button id="scale">
    scale
  </button>
  <div>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 409.96 254.59">
      <defs>
        <filter id="f1" >
          <feDropShadow  dx="1.5" dy="0.8" stdDeviation="1"/>
        </filter>
        <filter  id="f2">
          <feDropShadow dx="-2" dy="1.8" stdDeviation="1"/>
        </filter>
        <filter   id="f3" >
          <feDropShadow stdDeviation="10" dy="-4" dx="-2"/>
        </filter>
      </defs>
      <g filter="url(#f2)">
        <g filter=" url(#f3)">
      <path d="M167.1,52.17S209.77-28.24,301.66,10.6c0,0,59.62,23.52,56.34,96.81,0,0,55.45,16.41,51.79,79.86,0,0-.3,61.95-67.65,67.28H220.75q-72.56,0-145.12,0C29.57,254.66-2.8,215,.19,170.31c0,0,7.74-70,81.58-68.37C81.77,101.94,101.46,42.87,167.1,52.17Z" filter= "url(#f1)"></path>
        </g>
      </g>
    </svg>                            
  </div>
  <div>
  
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 409.96 254.59">
      <g filter= "url(#f2)">
        <g filter= "url(#f3)">
      <path d="M167.1,52.17S209.77-28.24,301.66,10.6c0,0,59.62,23.52,56.34,96.81,0,0,55.45,16.41,51.79,79.86,0,0-.3,61.95-67.65,67.28H220.75q-72.56,0-145.12,0C29.57,254.66-2.8,215,.19,170.31c0,0,7.74-70,81.58-68.37C81.77,101.94,101.46,42.87,167.1,52.17Z" filter= "url(#f1)"></path>
        </g>
      </g>
    </svg>                            
  </div>
</div>  

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

iPhone experiencing slow loading times with SVGs

I am currently in the process of building a website using Next.js and React, which is hosted on Heroku. To implement our grid system, we are utilizing the react-grid-system library, and for SVGs, we are using react-inlinesvg. Some of the SVGs are stored lo ...

Different ways to adjust the height of the date picker in Material UI

I am attempting to customize the mui date picker, but I am facing issues with applying CSS styles to it. I have tried using both inline styles and external styling by assigning classes, but nothing seems to work. I specifically want to adjust its height. ...

What steps should I take to ensure that jQuery functions remain functional on loaded code?

I have implemented modals on all my pages except for the first one to save time. Here is the script that loads my modals: $(function () { $('#header').load('reusenavbar.php'); $('#loginModal').load('reuseloginmo ...

Visual Studio Code version 1.42 is now automatically converting <br> tags to <br /> when formatting code

This issue just started occurring. I'm not exactly sure what triggered it, but it could be related to my attempt to activate the Preitter extension. As a newcomer to Visual Studio Code, I am currently working on HTML5 documents. Strangely, whenever I ...

Styling Labels with CSS Wildcard

I have been using the free NinjaForms plugin on my WordPress site. The default styling for labels is bold, but I prefer them to be lighter. Currently, I achieve this through CSS by targeting individual field IDs. However, this method becomes tedious when a ...

Personalizing MaterialUI's autocomplete functionality

Trying to implement the material-UI Autocomplete component in my react app and looking for a way to display a div when hovering over an option from the list, similar to what is shown in this reference image. View example If anyone has any tips or suggest ...

Stop the script if the folder has already been created

I have a question that might seem silly, but I'm struggling with this issue. I need the script to stop only if the folder in the directory already exists, but all I see is a blank page with the message "la cartella esiste" (the folder exists). I think ...

Modifying images through resizing and scaling within a flexible web application to accommodate different screen dimensions

With my web application, I have an image that changes in sizes as it calls a different image from the database each time it is viewed. My goal is to make sure this image is displayed responsively on different devices. For smartphones, I want the image to f ...

Activate on click using JavaScript

When a link with the class .active is clicked, I want to use a JavaScript function to deactivate any other active links. The structure of the code should be as follows: <ul class="product"> <li><a href="#myanmar" class="active">Mya ...

Creating Filled DIVs using JavaScript

Although it may appear to be a common inquiry, my specific needs have not been addressed in any of the Stack threads I've come across. I am dealing with a series of nested DIV statements, as demonstrated here (not all CSS included). I am looking to ...

How can jQuery be used to convert an ID into a string?

Currently, I am working with a jQuery function that interacts with an API and retrieves some data. Within this data, there is a specific piece of information that I need to manipulate. My goal is to replace instances where teamId = 100 with "Blue Team" an ...

Troubleshooting issues with applying styles in Vue framework when configured with webpack

I'm facing an issue with setting up the Vue framework using webpack. Specifically, I'm having trouble with styles not being applied when included in the <style> tag within single file components. Despite following several tutorials on this ...

Is it possible to create a replicating text box in AngularJS that multiplies when entering input

I am experimenting with creating a sequence of text boxes that dynamically generate new empty text boxes as the user enters information into each one. Each text box is required to have an ng-model value associated with it, and they should all be generated ...

The database powered by Postgresql performs flawlessly when it comes to updating data with accurate code execution. However, there seems to be an

Imagine a zoo with a postgresql database. To enable web access to this database, I am using php and javascript. Most of the web pages are working fine, but I am currently working on a page where clients can add or remove animals from existing exhibits. T ...

To enhance user experience, it is recommended to reload the page once

Hello, I'm looking for a way to automatically refresh the page after submitting an AJAX form. Currently, I have an onClick function that seems to refresh the page, but I still need to press F5 to see the changes I've made. Here's the JavaSc ...

Replacing a JSON vault using XHR: A step-by-step guide

Can someone assist me in replacing the JSON data from a JSON file on a website using JavaScript XHR? setagaya.json: {"trains":[{"operation_number":1,"line_id":26007,"station_id":784,"track_number":1,"up":true},{"operation_number":2,"line_id":26007,"stati ...

Easiest method to change cursor to 'wait' and then return all elements to their original state

On my website, there are certain CSS classes that define a specific cursor style when hovered over. I am trying to implement a feature where the cursor changes to a "wait" image whenever an AJAX call is initiated on any part of the page, and then reverts b ...

Physically moving the window to a specified location using window.scrollTo()

Whenever I use the window.scrollTo(); method upon clicking a button, it simply jumps to the destination without displaying the scrolling motion. How can I ensure that the window physically scrolls to the designated position instead of instantly appearing ...

Transferring Information between a Pair of Controllers

Currently, I am utilizing angular version 1.x and faced with the challenge of sharing data between two controllers. In my mainctrl, I am working with the above model. The radiotmplt.radiohead=='IRU600v3' is utilized in firstctrl. Unfortunately, ...

Is there a way to set a default CSS background image using JavaScript in case the specified

When working with regular CSS, I can easily set a fallback image using this code in case the primary image is not available: .container { background-image: url(pics/img.webp), url(pics/img.png); } But when it comes to setting styles in JavaScript (such ...