When Restarting, CSS3 Text Animation Overlaps First-Child Too Soon

http://jsfiddle.net/L7pV9/embedded/result/

If you're interested, I've provided a jSfiddle link where you can view the example.

I'm struggling to understand what's going wrong with my CSS3 animation. In my code, I have two span classes: one labeled Text1 and the other Text2.

During the animation, the words fade out and then the second label fades in, and vice versa. However, on the second run of the animation, label1 briefly reappears because it seems like label 2 is overlapping or overriding it. How can I prevent this glitchiness and make the labels smoothly transition?

It appears that when text2 finishes its animation, it triggers text1's animation again, creating a loop without giving text1 enough time to display.

Below is the snippet of CSS code:

.logoText{
    display: inline;
    padding: 3px 0 0 0;
}
.logoText span {
    background: #0c0d0f;
    padding-right: 100px;
    position: absolute;
    opacity: 0;
    overflow: hidden;
    float: left;

    color: #6f6f6f;
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 1px;
    text-transform: uppercase;

    -webkit-animation: fadeText 10s linear infinite 0s;
    -moz-animation: fadeText 10s linear infinite 0s;
    -o-animation: fadeText 10s linear infinite 0s;
    -ms-animation: fadeText 10s linear infinite 0s;
    animation: fadeText 10s linear infinite 0s;

}
.logoText span:first-child {
    background: #0c0d0f;
}
.logoText span:nth-child(2) { 
    background: #0c0d0f;
    -webkit-animation-delay: 5s; 
    -moz-animation-delay: 5s; 
    -o-animation-delay: 5s; 
    -ms-animation-delay: 5s; 
    animation-delay: 5s; 
}

The CSS-Animations keyframes are defined as follows:

@-webkit-keyframes fadeText {
0% { opacity: 0; -webkit-transform: translateY(-2px); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
97% { opacity: 1; -webkit-transform: translateY(0px); } 
98% { opacity: 0; -webkit-transform: translateY(2px); } 
100% { opacity:0; -webkit-transform: translateY(2px); }
}

Here's the HTML structure used:

          <div class="logoText">
                <span>Text1</span>
                <span>Text2</span>
            </div>

Answer №1

Your time distribution strategy is unique, resulting in:

@-webkit-keyframes fadeText {
    0% { opacity: 0; -webkit-transform: translateY(-2px); }
   10% { opacity: 1; -webkit-transform: translateY(0px); }
   97% { opacity: 1; -webkit-transform: translateY(0px); } 
   98% { opacity: 0; -webkit-transform: translateY(2px); } 
  100% { opacity:0; -webkit-transform: translateY(2px); }

}

You achieve full opacity for 87% of the duration (from 10 to 97); halfway opacity for 11%, and complete transparency only for 2%.

Therefore, most of the time, only the front div is visible.

If you desire an even time distribution, allocating 10% of the timeline to the transition would look like this:

@-webkit-keyframes fadeText {
    0% { opacity: 0; -webkit-transform: translateY(-2px); }
   10% { opacity: 1; -webkit-transform: translateY(0px); }
   50% { opacity: 1; -webkit-transform: translateY(0px); } 
   60% { opacity: 0; -webkit-transform: translateY(2px); } 
  100% { opacity: 0; -webkit-transform: translateY(2px); }
}

Ensuring the animation ends in the original state, perhaps consider starting with a positive Y translation (2px) instead?

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

Resizing objects within a section to conform to the section's dimensions is not possible in CSS/HTML

I'm facing some challenges with responsiveness on my landing page. Utilizing the scrollify jQuery library, users can skip between different sections of the landing page on click or scroll. However, when switching to landscape orientation on mobile d ...

Exploration of the "display: none;" property and loading of content

I am struggling to find concrete information on how "display: none;" affects content loading. I have always believed that certain browsers do not load external resources within content that is styled with "display: none". Is this still inconsistent across ...

The CSS3 scale() function leads to div elements appearing grainy

After experimenting with CSS3 animations, I've noticed that using the scale() function seems to cause pixelation on every element it's applied to. For example, check out this demo: http://jsfiddle.net/PD7Vh/2/ In the provided link, you can see ...

The background image is not visible

.imagem-cortada { width: 100%; background-image: url("imagens/Vector 9.png"); } The HTML: <section class="imagem-cortada conteudo-principal"><!--inicio sobre nos--> <div class="container"> ...

Troubleshooting problems with email templates using Handlebars JS within Nest JS

I am encountering an issue while using Handlebars JS in my Nest JS project to send emails. Although the email is sending properly, the content of the email body is not rendering correctly, resulting in responsiveness and styling problems. In my template: ...

Curved corners when an image is located on the border

Looking to create a basic website with React using Reactstrap and Bootstrap. I'm trying to add a custom border-radius to my Cards, but facing an issue where the image inside the Card is overlapping the container on the upper side. Is there a CSS prope ...

Troubleshooting CSS font-variation-settings not functioning

Exploring the possibilities of variable fonts has been my latest project. In my initial test, I played around with the font-variation-settings directive, but unfortunately, it doesn't seem to be functioning properly. This was evident on both Codepen: ...

Span is the alternative to using breaks in XHTML, but unlike breaks, it does not allow for adding padding or margin

When working with xhtml, I encountered an issue where my description and header elements were not position correctly next to my image. I initially used div elements instead of span, which violated xhtml rules. Then I tried using span elements, but I was un ...

Why do images not show up when they are in the same directory in HTML?

article.uk{ background-image: url("GB_Flag.jpg"); background-color: #95a5a6; background-repeat: no-repeat; background-position: right top; width: 75%; background-size: contain; color:#d98880; } <a href="GB.html" target="Great_Britain_Page"> < ...

Firefox having trouble displaying styles correctly

I just finished creating a website for my band, but I am having issues with it displaying correctly in Firefox. While everything looks great in Chrome and Safari, it seems like the stylesheet isn't loading at all in Firefox, leaving the page looking u ...

Ways to reduce the size of a Select box when the option text is too lengthy

How can I reduce the size of the select box by splitting the lines of the options I attempted to modify the CSS with: select { width:100px; } However, only the select element was affected. The options remained the same size. My goal is to have ...

The active link color for navigation in Bootstrap 4

I am trying to update the active menu links to display in green on my website. Despite various attempts, I have not been successful in changing the color. Can anyone provide guidance on how to proceed? My website is built with Bootstrap 4 and mdbootstrap. ...

What is the best way to adjust the size of an SWF object using a Blueprint CSS span range?

Utilizing Blueprint CSS, I am crafting a 3 column layout: LEFT COLUMN: span-6 CENTER COLUMN: span-12 RIGHT COLUMN: span-6 Within the center column, I aim to insert an SWF object that requires a predetermined size upon setup: swfobject.embedSWF(url, "fla ...

Use Flexbox hover effect to display submenu text exclusively in the column being hovered

Having an issue with a 5 column flexbox. Each box should display a header text and supplementary text only when hovered over, returning to normal when unhovered. I was able to accomplish this in Codepen (view the rough model here). However, when trying to ...

Develop your website layout with Flexbox (Bootstrap 4.2), using stacked grid designs similar to the float: left method

For my Wordpress theme, I am utilizing Bootstrap 4.2 to design a basic grid layout for a list of blog posts. In my design, I have a Card that is double the height of others and I am attempting to 'float' two single-height cards beside it. Previ ...

How can I make a div collapse in the same way as the Facebook chat

I am working on creating a chat feature similar to Facebook chat for personal use. Everything is functioning correctly, except for some issues with the CSS. I attempted using position absolute to arrange the div, which worked fine, but encountered problem ...

Is there a more efficient method for submission? I wonder if there is an optimal approach for this task

Here is my existing code snippet: CSS: .submitorder { background-image: url('https://www.amleo.com/images/art/PON1.jpg'); width: 205px; height: 52px; font-size:0px; } .submitorder:hover { background-image: url('https://www.amleo.com/image ...

Struggling to minimize the dimensions of the Image div in React Js with Tailwind CSS

I am currently working on replicating the functionality of the Book My show Application. Specifically, I am developing a Cast and Crew slider. Despite my efforts to decrease the size of the images, the spacing between them remains unchanged. Here is my Ja ...

Flickering in CSS transitions on Microsoft Edge

There seems to be a peculiar issue with CSS transitions in Microsoft Edge. The problem arises when there is a transition, such as between hover states, but the styles specified for those states are overridden by other styles in the CSS hierarchy. In such ...

Angular components are experiencing issues with Material UI checkboxes due to CSS overrides

Currently, I have successfully overridden the CSS of a Material UI checkbox in my Home Component. However, this has caused some unintended side effects such as overriding the CSS of checkboxes in other components, like the form component. Does anyone have ...