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

Update the background color of an li element upon clicking

Is there a way to change the background color upon clicking on the li anchors? <div class="text-center row"> <ul class="col-md-12 secondNav"> <li class="navbar-brand nav-item" style="margin-right: 9%"> <a href="#" >& ...

Switching button appearance when hovered over

Looking to create a page layout with 4 buttons, each occupying one quadrant of the page? These buttons should feature images as their background and change to different images when hovered over. Wondering how this can be achieved using CSS? ...

The initial item in the Materializecss slider is failing to display

Currently, I am attempting to implement materialize slider with skrollr. The setup is functional; however, only the first item of the slider is set to opacity: 0 initially. https://i.stack.imgur.com/urSww.jpg After a brief delay, the second item becomes ...

Random image generator using jQuery on the home page body

Hey guys, I'm working on a cool feature for my Wordpress site where a random background image loads every time the homepage is refreshed. Check out the code snippets below: First, here's what I have in my style sheet (style.css): body.home { ...

Place the Div directly above a distinct Div

Hey there! I'm currently working on positioning one div on top of another div programmatically (using javascript or css). These divs are completely separate and have the following structure: <div class="bottom"> <img src="image"></i ...

Creating a single row with five columns using HTML and CSS

I'm currently working on setting up a layout consisting of 1 row and 5 columns placed side by side. These columns are going to showcase the projects that I intend to feature on my online Portfolio. To achieve this layout, I am utilizing the Bootstrap ...

What are some ways to slow down the speed of a canvas animation?

I am currently working on an animation project using JavaScript and canvas. I have a reference fiddle where objects are generated randomly and fall from the top right corner to the bottom left corner, which is fine. However, the issue is that the objects a ...

What's the reason for the inability to resize fieldset using both?

Can someone explain why the resize control is not enabled on the fieldset element? The documentation mentions that resize does not work with: Inline elements Block elements that have overflow set to visible fieldset { resize: both; overflow: h ...

Surprising sight of a blank canvas behind the font-awesome icon

Is there a way to remove the unexpected white background that appears when adding a font-awesome icon? Here is the HTML code: <div class="notifications-window" id="close-notifications"> <div class="notifications-header&qu ...

Having trouble extracting data from Moz Bar through selenium using Python?

Having trouble retrieving the spam score from Moz bar using Selenium WebDriver? I've attempted various methods such as XPath, class, and tag name without success. Any assistance would be greatly appreciated: from selenium.webdriver.common.by import By ...

Click to reveal the hidden div located at the bottom of the webpage

I have created a simple webpage where all the content is visible without the need to scroll down. However, there is additional content at the bottom that I want to keep hidden until the user chooses to see it. The idea is to have a phrase at the bottom o ...

Issues with CSS transitions not functioning properly following the use of toggleClass()

I recently implemented a toggle-menu feature, which you can see in action on this demo. To enhance the toggle-menu, I added a CSS transition effect to div.nav-menu, utilizing max-height:0; and increasing it to max-height:480px;. However, after clicking t ...

Navigate to specific element from bootstrap navigation bar

I am in the process of creating a website for a small organization. The website is being constructed using bootstrap 4, and there is a navbar that connects to various flex-containers. I want these connections to smoothly scroll to their respective elements ...

CSS - text featuring a gentle shadow hue and a deeper foreground color

I'm encountering an aesthetic issue where my list of texts have random light/bright colors, making them hard to read on white backgrounds. I've tried setting the text color to shadow, but now I want the text itself to be a darker, more readable c ...

Tips for enabling the wrap property with autogeneratecolumn set to true

In my grid view, I want to ensure that any text in a column that exceeds the width of the column will either wrap within the column or display on a new line. Below is the code for the grid view: <asp:GridView ID="GridView1" AllowSorting="True" runa ...

Positioning a sticky footer in a dual-column design

This updated post is a revised version of the one found at this link. I aim to provide a clearer explanation of my issue compared to the previous post. The problem revolves around the placement of the footer in two different scenarios. Scenario 1: https: ...

jQuery accordion section refuses to collapse

In order to achieve the desired outcome, each Section should initially appear in a collapsed state. Panel 0 and 2 start off collapsed, however, panel 1 does not but can be collapsed upon clicking. Additionally, Panel 1 incorporates an iframe that displays ...

I can't seem to get my SVG data URL located inside an HTML file within an SVG data URL to display in Chrome

Background I am encountering an issue where an SVG data URL used as a background image property inside an HTML element within a <foreignObject> nested within an SVG data URL is not rendering properly in Google Chrome. If this structure was outside o ...

Utilizing JQuery for adjusting the CSS top property

I needed to overlay text on an image, so I used CSS for this purpose. However, as I incorporated Bootstrap and hesitated to include absolute positioning in the CSS file, I faced issues with centering the text when resizing the image. To tackle this problem ...

`Implementing a dynamic list with image and button using Bootstrap 5`

I've been exploring ways to create a container with 4 images aligned next to each other, accompanied by a button beneath each image. My goal is for the layout to be responsive, meaning that as the screen size adjusts, the elements inside should also a ...