"Utilize CSS for animating list items within a ul

Having an unordered list, I would like to iterate through each list item one by one. My current solution is somewhat functional, but upon close inspection, you can observe that when it reaches "item 4," it starts overlapping with "item 1" and becomes inconsistent.

@keyframes fadein {
  0% {
    opacity: 0;
  }
  66% {
    opacity: 0;
  }
  76% {
    opacity: 1;
  }
  100% {
    opacity: 1;
  }
}

li {
  list-style: none;
  padding: 0;
  font-size: 40px;
  position: absolute;
  width: 100%;
  opacity: 0;
}

li:nth-of-type(1) {
  animation: fadein 6s ease-in-out -4s infinite alternate;
}

li:nth-of-type(2) {
  animation: fadein 6s ease-in-out 0s infinite alternate;
}

li:nth-of-type(3) {
  animation: fadein 6s ease-in-out 4s infinite alternate;
}

li:nth-of-type(4) {
  animation: fadein 6s ease-in-out 8s infinite alternate;
}
<ul class="usp__list">
  <li class="usp__item">
    Item 1
  </li>
  <li class="usp__item">
    Item 2
  </li>
  <li class="usp__item">
    Item 3
  </li>
  <li class="usp__item">
    Item 4
  </li>
</ul>

If anyone could assist in resolving this issue, it would be greatly appreciated. I assume it has something to do with the delay, but despite trying many variations, I am still facing this underlying problem.

Fiddle - https://jsfiddle.net/15c4rd8v/

Answer №1

Your animation-duration is inadequate. While you have an animation-delay set to a maximum of 8s, the duration is only 6s, resulting in a 2s overlap. Adjusting the duration to 8s and modifying your keyframes animation from ...66% {...} 76%... to 75% {...} 80%... will resolve this issue.

@keyframes fadein {
  0% {
    opacity: 0;
  }
  75% {
    opacity: 0;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 1;
  }
}

li {
  list-style: none;
  padding: 0;
  font-size: 40px;
  position: absolute;
  width: 100%;
  opacity: 0;
}

li:nth-of-type(1) {
  animation: fadein 8s ease-in-out -4s infinite alternate;
}

li:nth-of-type(2) {
  animation: fadein 8s ease-in-out 0s infinite alternate;
}

li:nth-of-type(3) {
  animation: fadein 8s ease-in-out 4s infinite alternate;
}

li:nth-of-type(4) {
  animation: fadein 8s ease-in-out 8s infinite alternate;
}
<ul class="usp__list">
  <li class="usp__item">
    Item 1
  </li>
  <li class="usp__item">
    Item 2
  </li>
  <li class="usp__item">
    Item 3
  </li>
  <li class="usp__item">
    Item 4
  </li>
</ul>

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

Tips for customizing the selected and hover color of ListItem in Material UI

Having trouble getting the 'selected' or 'hover' colors to work for the ListItem component. I've tried setting its classes like this: <ListItem selected button key="home" classes={{ selected: classes.listItemSelected } ...

Error encountered when using Symfony 2 command line interface

Just started learning Symfony2 and encountered a problem. I made changes to my CSS and when I try to re-install them in Eclipse shell, I get this error message: 'C:\wamp\www\Symfony' is not recognized as an internal or external ...

What is the optimal unit to employ in CSS - percentages or pixels?

As someone who is not well-versed in CSS, I strive to create a design that will appear visually appealing across all browsers and screen resolutions. I have observed that certain websites construct their designs using percentages for properties like width, ...

Creating a WordPress Infographic: How to Design a "Wide" Graphic

I have a question for those who are experienced with infographics. I'm in the process of getting an infographic designed for my blog and I've noticed that some websites have a feature that allows the infographic to expand to full width when you c ...

"Master the art of creating a curved circular arrow using a combination of HTML, SVG, D3.js

I am looking to design an SVG circle with a fading stroke that blends into the background and features an arrow at one end. The goal is for the ring to fade out completely right above the arrow, similar to the visual reference provided in the image.view ex ...

Enlarging the font size of a specific <a> element dynamically with JavaScript, while ensuring that the padding of surrounding <a> elements remains

I have the following code snippet to display 3 links side by side: <div class="col-xl-9 col-lg-9"> <div class="main-menu d-none d-lg-block"> <nav> <ul id="navigation"> ...

Undetected gap within boundaries

I have a container that contains four div elements. Each inner div has an absolute position and the same size. When I add borders to the inner divs, instead of creating circles, I end up with something that looks like a sliced cake: https://i.sstatic.net/ ...

I desire for my div elements to stack on top of each other

Struggling to get my images to overlap no matter what positions I try. HTML Code: <li class="six"> <img class="06a" src="../inhouds/images/page06a.png"> <img class="06b" src="../inhouds/images/page06b.png"> <img class="06c" src=".. ...

Iterating through an SVG path multiple times

If I have the arrow below and I want to place it at various locations within the svg: <svg width="400" height="400"> <path transform="translate(150,100)" fill="black" d="M 0.5,0.5 l-100,0 -25,20 25,20 100,0 z" /> <path transform="translate( ...

Ensure the footer remains fixed while scrolling

For the past day, I've been tackling a challenge with my online shop project. On the specific item's page, I want to include a fixed [add to cart] button as a footer initially, which then becomes sticky when scrolling to a certain point. You can ...

The button is obscured by the dropdown menu

Here is the code snippet I am working with: HTML <nav class="navbar bg-dark navbar-dark"> <div class="container-fluid"> <div class="navbar-header"> <a href="#" class=&quo ...

What happens to the page layout when a user adjusts the window size?

Is there a way to ensure that a div remains at 40% of the full screen width, regardless of window size changes? I am looking for a JavaScript or JQuery code that can lock the setting of the div to always be 40% of the full screen size. <div style="wi ...

Allow clicking through the iframe, while still able to interact with its contents

I am facing a challenge of making an iframe click-through, while ensuring that the body of the iframe remains clickable. I have attempted to achieve this using the following code: iframe.style.width = '100%' iframe.style.height = '100%&apos ...

Is JSF h:outputStylesheet converter the solution for creating dynamic CSS?

Recently, I came across the <h:outputStylesheet/> tag with a converter attribute. I tried attaching a dummy (pass-through) converter to it, but to my surprise, nothing happened. Upon further investigation, it appears that the converter is not even in ...

How can I create two left-aligned columns in CSS, with the first column being fixed in place?

Is there a way to create two columns without using HTML tables? I'm looking for the first column to contain an image and the second column to display text aligned left, extending to the rest of the page width. I found this CSS solution for the first ...

Adaptable Image Functionality in Jquery Carousel

I've encountered an issue with my images within a jquery slider. While the slider itself is functioning properly, I am facing a couple of challenges. Initially, I aimed to make the images responsive, but upon removing the height property, the content ...

Issue with absolute positioning in IE6 and IE7 not functioning correctly

I recently created a website for a friend that involves absolute positioning within a relative positioned div. After testing it in various browsers using Browserlabs, I found that it works well except for IE6 & IE7. Despite searching online for solut ...

Tips for avoiding a ligature occurrence in a specific location

I am a fan of ligatures in general, as they improve readability. I want to implement them across all my HTML pages. However, there is this one word Hanftierheft (which is German and a compound word made up of Hanf, Tier, and Heft). I specifically do not w ...

Conflicting jQuery slide effects and jQuery UI positioning causing issues

As you hover over an element, the position function adjusts its left attribute to the correct value. However, when you move the mouse away, it resets back to 0, causing the element to appear below the first one in the list. This issue is noticeable when y ...

Apply CSS styles from a text area using v-html

I am currently working on developing a unique WYSIWYG application where users have the ability to write CSS in a textarea field and view its direct impact on the HTML content displayed on the page. As I was experimenting with different approaches, I attemp ...