Special characters are causing the fill effect to malfunction

When the effect is applied to a single word without spaces or special characters, it works perfectly. However, as soon as I add another word, the effect immediately glitches.

Codepen

/* Text-fill */

.text-fill {
  position: relative;
  font-size: 100px;
  font-weight: bolder;
  -webkit-text-fill-color: white;
  -webkit-text-stroke: 2px black;
  transition: 0.3s;
  overflow: hidden;
  width: fit-content;
}
.text-fill::before {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  -webkit-text-fill-color: cornflowerblue;
  width: 0%;
  overflow: hidden;
  transition: 1s;
}

.text-fill:hover::before {
  width: 100%;
}
<!-- text fill  -->
<p class="text-fill" data-text="WEB">WEB</p>
<p class="text-fill" data-text="Web Development">Web Development</p>

Answer №1

The code is functioning correctly without any additional modifications. It's possible that there was a misinterpretation of the question, but it seems like the data-text attribute was not completed after wrapping the text within the paragraph tags <p>

  • A demonstration featuring extended content

/* Text-fill */

.text-fill{
    position: relative;
    font-size: 100px;
    font-weight: bolder;
    -webkit-text-fill-color: white;
    -webkit-text-stroke: 2px black;
    transition: 0.3s;
    overflow: hidden;    
    width: fit-content;
}
.text-fill::before{
    content: attr(data-text);
    position: absolute;
    left: 0;
    top: 0;
    -webkit-text-fill-color: cornflowerblue;
    width: 0%;
    overflow: hidden;
    transition: 1s;
}

.text-fill:hover::before{
    width: 100%;
}
<!-- text fill  -->
<p class="text-fill" data-text="A demonstration featuring extended content">A demonstration featuring extended content</p>
<p class="text-fill" data-text="Another example with more text">Another example with more text</p>

The animation might be too sluggish on mobile devices.

  • An illustration utilizing characters, behaves similarly to plain text.

/* Text-fill */

.text-fill{
    position: relative;
    font-size: 100px;
    font-weight: bolder;
    -webkit-text-fill-color: white;
    -webkit-text-stroke: 2px black;
    transition: 0.3s;
    overflow: hidden;    
    width: fit-content;
}
.text-fill::before{
    content: attr(data-text);
    position: absolute;
    left: 0;
    top: 0;
    -webkit-text-fill-color: cornflowerblue;
    width: 0%;
    overflow: hidden;
    transition: 1s;
}

.text-fill:hover::before{
    width: 100%;
}
<!-- text fill  -->
<p class="text-fill" data-text="?±!@#$%^&*">?±!@#$%^&*</p>
<p class="text-fill" data-text="水山人口刀木日月女子馬鳥目">水山人口刀木日月女子馬鳥目</p>

To enhance performance and prevent lag, consider reducing the text length to avoid displaying it on two lines.

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

The problem with maintaining a 100% height background image size is persisting

After making progress on the background of my new website, I've hit a roadblock. The background image shrinks to less than 100% height when the browser window is resized. I need the background image to remain full size at all times, without the heigh ...

Experiencing issues with overflowing columns in JQuery Datatables

I am currently facing an issue with my datatable where I need it to have a specific width while also displaying all its columns. The problem I am encountering can be summarized as follows: I came across solutions like Datatables Width Overflow For A ...

Transform content div into a clickable element by incorporating nested divs

Here is my current layout: <div id="content"> <div id="img"><img src=""></div> <div id="main">Some content</div> <div id="btn" class="hidden"><button>Submit</div> <div class="hidden">Some ...

Adjusting the spacing around the title of a post when the text wraps

This website has some great resources, check it out! In the right sidebar, there seems to be an issue with the CSS when the h4 heading wraps onto two lines. The margin and padding at the bottom of the heading are not spacing properly. I've tried adju ...

Attempting to relocate the final two links within my navigation div to the opposite side of the container div

Hey there! I've been trying to figure out how to move my 'Facebook' and 'Twitter' links to the right side of my navigation bar while keeping all the other links on the left. It's been quite a challenge so far! I've been ...

Exploring potential methods for generating a PDF invoice in PHP and CodeIgniter by utilizing HTML elements

Greetings everyone, I have encountered a common question on stackoverflow. I am currently working on an HTML invoice template similar to the one showcased in this demo page. My goal is to create a PDF file of the invoice when users click on a specific butt ...

What is the best way to style only textboxes with CSS without affecting other input types such as checkboxes?

If attribute selectors were universally supported by all browsers, we could effortlessly implement the following styling: input[type='text'] { font:bold 0.8em 'courier new',courier,monospace; } input[type='radio'] { margin:0 ...

How can I modify the content within a scoped `<style>` tag in Vue?

Is there a way to dynamically change the contents of a <style> block in my Vue component using Vue variables? Many commonly suggested solutions involve inline styles or accessing the .style property with JavaScript. However, I am looking for a metho ...

The ellipsis menu pops up next to the final video in the series of HTML videos

Currently, I am working on rendering HTML video tags for playing videos. However, I am facing an issue where the three dots menu is not appearing near the button that triggered it, instead, it displays near the last video's three dots. To illustrate t ...

Start your slideshow automatically (with an option to toggle)

http://jsfiddle.net/r6uf38v4/ After the page loads, my goal is to have the slider begin automatically. However, I also want to provide the option for users to pause it using a checkbox and then resume the slider. $('#checkbox').change(function( ...

Find and retrieve all data attributes with JavaScript

What is the method to retrieve all data-attributes and store them in an array? <ul data-cars="ford"> <li data-model="mustang"></li> <li data-color="blue"></li> <li data-doors="5"></li> </ul> The resultin ...

Center-align the text by disregarding the absolutely positioned element

I have created a custom flex table with filtering and sorting capabilities. The filter and sort icons are located in the right corner of the table header. Additionally, users can choose to align the header text left or center. The Issue: When positioning ...

Including a Script Tag in an Angular 2 Application with a Source Attribute retrieved from a Web API Request

Situation: Within my Angular 2+ application, I am utilizing a web API to retrieve URLs for script tags created by a function called loadScript during the AfterViewInit lifecycle hook. The web API is providing the expected JsonResult data, which I have suc ...

setTimeout in CSS animation causing issues

I recently created an animation using CSS3. The source code is quite simple. It involves displaying text and then making it disappear after 4 seconds. Below you can find the current source code: const intro1 = document.getElementsByClassName('intro ...

A method for positioning each pair of <li> elements side by side

My goal is to arrange every pair of li elements next to each other (e.g. 0-9, A-B, C-D, ...). Currently, they are aligned one by one. <ul> <li class="alphabetRow"><a href="#" id="alpha_1" class="alphabet active" >0-9</a></li ...

Does HTML5 officially provide the speechsynthesis API for users?

Can someone clarify if speech synthesis is officially supported by HTML5 for converting text-to-speech? ...

Receiving a 502 Bad Gateway error when attempting to request a CSS file via HTTPS

After recently adding SSL to some pages on my website, I encountered an issue when trying to call a secured web page <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="https:/ ...

Update the bootstrap button's value when clicking on it

Looking to change the content of a button upon clicking it - specifically transitioning it to a "block" state where it becomes unclickable, all while displaying a Glyphicon icon. Here's what I want to include: <span class="glyphicon glyphicon-sav ...

Arranging multi-level array with distinct keys and values

Users have the ability to add custom fields on a form. Note: I am looking for ways to streamline and organize the code more efficiently, with further explanations to follow. https://i.sstatic.net/2xMQe.jpg The HTML structure has been simplified for clar ...

Horizontal rule spans the full width of the content, appearing within an ordered list

Check out this example to see the issue with the horizontal rule not extending all the way across under the number. I've tried using list-style-position:inside;, but that interferes with positioning the number correctly due to the left image being flo ...