Incomplete filling of the SVG element is observed

Trying to animate SVG text to display only the outer stroke of each letter initially, followed by filling the interior with color. However, after the animation finishes, there are unfilled spaces left. Is there a property that can be applied to the SVG or paths to completely fill the inside of each letter without increasing the stroke thickness? (In order to maintain the initial appearance of the animation) See example below:

<svg id="testSVG" width="312" height="219" viewBox="0 0 312 219" fill="none" xmlns="http://www.w3.org/2000/svg">
    <mask id="path-1-outside-1" maskUnits="userSpaceOnUse" x="0.632004" y="0.312012" width="311" height="219" fill="black">
    <rect fill="white" x="0.632004" y="0.312012" width="311" height="219"/>
    <path d="M13.152 52H6.896V3.31201H13.152V24.188H37.496V3.31201H43.752V52H37.496V30.036H13.152V52Z"/>
    </* more paths here */>
</svg>
#testSVG path:nth-child(2) {
    //H
    stroke-dasharray: 256.77;
    stroke-dashoffset: 256.7679443359375;
    animation: svgfill 1s ease forwards;
}

#testSVG path:nth-child(3) {
    //A
    stroke-dasharray: 236.68453979492188;
    stroke-dashoffset: 236.68453979492188;
    animation: svgfill 1s ease forwards;
}

/* remaining CSS code */

@keyframes svgfill {
    to {
        fill: white;
    }
}

Answer №1

Here is an innovative approach that involves creating a white version of your shape overlaying the original, which is then gradually eroded away. While it may not be as seamless as your method, it offers improvements in certain aspects.

<svg id="testSVG" width="312" height="219" viewBox="0 0 312 219" fill="none" xmlns="http://www.w3.org/2000/svg">
        <defs>
        <filter id="erode-animate">
          <feMorphology radius="0" operator="erode">
            <animate attributeName="radius" from="0" to="5" by="0.2" dur="1s" fill="freeze"/>
          </feMorphology>
          
        </filter>
        </defs>
        
        <path d="M13.152 52H6.896V3.31201H13.152V24.188H37.496V3.31201H43.752V52H37.496V30.036H13.152V52Z" stroke="#D97E9F" stroke-width="2" fill="#D97E9F" />
<path d="M71.1932 10.996L63.2372 32.96H79.4212L71.4652 10.996H71.1932ZM56.3692 52H49.4332L67.7932 3.31201H74.8652L93.2252 52H86.2892L81.5972 38.808H61.1292L56.3692 52Z" fill="#D97E9F" stroke="#D97E9F" stroke-width="2"/>
<path d="M105.191 32.28V52H98.9351V3.31201H115.527C119.743 3.31201 123.324 4.71734 126.271 7.52801C129.263 10.3387 130.759 13.7613 130.759 17.796C130.759 21.9213 129.263 25.3667 126.271 28.132C123.37 30.8973 119.788 32.28 115.527 32.28H105.191ZM105.191 9.29601V26.296H115.663C118.156 26.296 120.219 25.4573 121.851 23.78C123.528 22.1027 124.367 20...
<path d="M192.206 29.356V52H185.95V29.356L169.562 3.31201H176.906L188.942 23.1H189.214L200.978 3.31201H208.322L192.206 29.356Z" fill="#D97E9F" stroke="#D97E9F" stroke-width="2"/>
        
<g filter="url(#erode-animate)">
<path d="M13.152 52H6.896V3.31201H13.152V24.188H37.496V3.31201H43.752V52H37.496V30.036H13.152V52Z" fill="white" />
<path d="M71.1932 10.996L63.2372 32.96H79.4212L71.4652 10.996H71.1932ZM56.3692 52H49.4332L67.7932 3.31201H74.8652L93.2252 52H86.2892L81.5972 38.808H61.1292L56.3692 52Z" fill="white"/>
<path d="M105.191 32.28V52H98.9351V3.31201H115.527C119.743 3.31201 123.324 4.71734 126.271 7.52801C129.263 10.3387 130.759 13.7613 130.759 17.796C130.759 21.9213 129.263 25.3667 126.271 28.132C123.37 30.8973 119.788 32.28 115...
<path d="M192.206 29.356V52H185.95V29.356L169.562 3.31201H176.906L188.942 23.1H189.214L200.978 3.31201H208.322L192.206 29.356Z" fill="white"/>
        </g>
</svg>

Answer №2

To improve code readability and ease of debugging, consider simplifying and commenting on the code as much as possible. Here are some potential strategies:

  • Replicate paths with no stroke and then fill them
  • Use CSS to animate the filling directly
  • Group each letter for improved organization

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

Conceal or reveal buttons using JavaScript

I am struggling with a function that is supposed to hide certain buttons and create a new button. When I click on the newly created button, it should make the previously hidden buttons visible again. However, the function does not seem to work properly. ...

Dragging and dropping elements onto the screen is causing them to overlap when trying

I am having trouble merging the drag and drop functionality from Angular Material with resizing in a table. Currently, both features are conflicting and overlapping each other. What I am hoping for is to automatically cancel resizing once drag and drop s ...

What is the best method for placing an element above all other elements on a page, regardless of the layout or styles being used?

I want to create a sticky button that remains fixed on the page regardless of its content and styles. The button should always be displayed on top of other elements, without relying on specific z-index values or pre-existing structures. This solution must ...

What is the best way to utilize MUI breakpoints for displaying images based on different screen sizes?

I need help displaying an image based on the screen size using MUI breakpoints. I'm struggling to understand how to implement this with MUI. Can someone assist me with the breakpoints? interface EmptyStateProps { title: string; description: string ...

Creating custom designs for Material UI components

Although not a major issue, there is something that bothers me. I am currently using react, typescript, and css modules along with . The problem arises when styling material ui components as I find myself needing to use !important quite frequently. Is th ...

Animate a jumping figure using jQuery

Is it possible to create an animation of a person jumping from the bottom of the screen to the top, with the scroll bar following them? I have my doubts but would love to know if it can be done. If you want to see what I mean, check out this PDF: http:// ...

Having trouble achieving the desired effect with inline block

I'm having some trouble creating a simple store page. One of the products is supposed to look like this: However, it's currently showing up like this: I've been attempting to use inline block so that I can have the negotiate button and pro ...

Replace !important with JavaScript/jQuery when using animate()

I need to animate the background-position-x, but there is a background-position: 0 0 !important; set in the css that cannot be removed. Is it possible to work around this using JavaScript? My jQuery code is functioning as intended, but it is being overridd ...

Steer clear of pre-made CSS divs when incorporating them into your

I have created a CSS file that includes the following styles for div elements: div { height:auto; float:left; padding:0px; margin:0px; overflow:hidden; text-align:left; width:auto; } img { border:none; } ul { padding:0; margin:0; } ...

What causes the position: sticky; property to fail in React implementations?

Currently, I am facing a challenge in making two sidebars sticky so that they will follow as the user scrolls until they reach the bottom of the page. In my current editing project, this implementation seems to be more complex compared to other programs w ...

The webpage must be designed to be compatible with screen resolutions starting from 800 x 600 pixels and higher, utilizing Angular

I am working on developing a webpage that is specifically designed to work for resolutions of 800 x 600 pixels and higher. Any other resolutions will display the message "This website can only be accessed from desktops." Here is my approach using jQuery: ...

Is it possible to create this design using CSS?

I attempted to break away from the conventional square layout of the internet with this design, but I am struggling to utilize Z-index to layer the backgrounds effectively. Here is the current code: <!--############################################# ...

Discover the way to create an HTML button with a mesmerizing transparent effect

For my website creation using Dreamweaver, I came up with the idea of utilizing Photoshop to design backgrounds. The reasoning behind this choice was that if I needed to modify button names at any point, I could simply edit the code and make the necessary ...

Illustration: Fixing a CSS Issue

After implementing Technique #8 from the Nine Techniques for CSS Image Replacement, I am not getting the desired results. Instead of correctly positioned images, the output is not what I anticipated. Here is a link to see for yourself: I made a modificati ...

Display the field names from a MySQL table on a web page

Is there a way to show all column names from a MySQL table on a webpage if only the table name is known? ...

Tips for avoiding table column overlap during window resizing situations

My current issue involves using a table to present information. While resizing the window, I noticed that the columns in the table were overlapping. Below is the code snippet: <table style="width:100%;table-layout:fixed"> <tr style="border-bo ...

What is the best way to add color to a Table Header?

I'm working on a HTML/CSS table and I want the header row to have a specific background color. Below is my code: <table class="contentTable"> <tr class="contentTableHeader"> <th>No.< ...

Add formatting to a particular element without affecting elements within another element

Consider the following scenario: <input type='text' /> <br /> <iframe> <input type='text'> </iframe> With the style defined as: input[type='text'] { border: 1px solid black; } If you w ...

How to retrieve the width of a document using jQuery?

Having a strange issue with determining the document width using $(document).width() during $(window).load and $(window).resize. The problem arises when the browser is initially full screen and then resized to a narrower width, causing content to require ...

Leveraging React Native to position a view absolutely in the center of the screen without obstructing any other components

How can I center an image inside a view in the middle of the screen using position: "absolute"? The issue is that the view takes up 100% of the width and height of the screen, causing all components underneath it (such as input fields and buttons ...