Is it possible to increase the delay in the nth-child selector?

I'm attempting to create a compact checklist that displays in a single row with items appearing sequentially. To achieve this, I utilized the :nth-child() selector in CSS as shown below:

.animated {
  -webkit-animation-duration: 0.8s;
  animation-duration: 0.8s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
  -webkit-animation-timing-function: ease-out;
  animation-timing-function: ease-out;
}
.animated:nth-child(2) {
  animation-delay: 1s
}
.animated:nth-child(3) {
  animation-delay: 2s
}
.animated:nth-child(4) {
  animation-delay: 3s
}
@-webkit-keyframes fadeInUp {
  0% {
    opacity: 0;
    -webkit-transform: translateY(20px);
  }
  100% {
    opacity: 1;
    -webkit-transform: translateY(0);
  }
}
@keyframes fadeInUp {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
.fadeInUp {
  -webkit-animation-name: fadeInUp;
  animation-name: fadeInUp;
}
.checklist_table {
  border-radius: 10px;
  padding: 10px;
  background: #eee;
  margin: 0 auto;
  width: 80%;
}
.checklist_table tr {
  width: 100%;
}
.checklist_table td {
  padding: 10px;
  width: 20%;
  text-align: center;
}
.checklist_table td:nth-child(2) {
  padding: 10px;
  width: 80%;
  text-align: left;
}
<table class="checklist_table">
  <tr>
    <td>
      <img src="checkmark.png" width="50px" class="animated fadeInUp" />
    </td>

    <td>
      <p class="status_checklist_p">1</p>
    </td>
  </tr>
  <tr>
    <td>
      <img src="checkmark.png" class="animated fadeInUp" width="50px" />
    </td>

    <td>
      <p class="status_checklist_p">2</p>
    </td>
  </tr>
  <tr>
    <td>
      <img src="checkmark.png" class="animated fadeInUp" width="50px" />
    </td>

    <td>
      <p class="status_checklist_p">3</p>
    </td>
  </tr>
</table>

View Fiddle Demo

Although the animation is functioning correctly, the delay feature seems to be ineffective. What am I missing in my implementation?

Answer №1

When it comes to animation delay, the selectors currently in use do not have any effect due to the fact that they are not selecting any elements. This is because each img element with a class='animated' happens to be the first and only child of its parent td, resulting in no selection by the selector.

To overcome this issue, it is recommended to apply the selector based on the index of the child element of the tr.

.animated {
  -webkit-animation-duration: 0.8s;
  animation-duration: 0.8s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
  -webkit-animation-timing-function: ease-out;
  animation-timing-function: ease-out;
}
tr:nth-child(2) .animated {
  animation-delay: 1s
}
tr:nth-child(3) .animated {
  animation-delay: 2s
}
.animated:nth-child(4) {
  animation-delay: 3s
}
@-webkit-keyframes fadeInUp {
  0% {
    opacity: 0;
    -webkit-transform: translateY(20px);
  }
  100% {
    opacity: 1;
    -webkit-transform: translateY(0);
  }
}
@keyframes fadeInUp {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
.fadeInUp {
  -webkit-animation-name: fadeInUp;
  animation-name: fadeInUp;
}
.checklist_table {
  border-radius: 10px;
  padding: 10px;
  background: #eee;
  margin: 0 auto;
  width: 80%;
}
.checklist_table tr {
  width: 100%;
}
.checklist_table td {
  padding: 10px;
  width: 20%;
  text-align: center;
}
.checklist_table td:nth-child(2) {
  padding: 10px;
  width: 80%;
  text-align: left;
}
<table class="checklist_table">
  <tr>
    <td>
      <img src="checkmark.png" width="50px" class="animated fadeInUp" />
    </td>

    <td>
      <p class="status_checklist_p">1</p>
    </td>
  </tr>
  <tr>
    <td>
      <img src="checkmark.png" class="animated fadeInUp" width="50px" />
    </td>

    <td>
      <p class="status_checklist_p">2</p>
    </td>
  </tr>
  <tr>
    <td>
      <img src="checkmark.png" class="animated fadeInUp" width="50px" />
    </td>

    <td>
      <p class="status_checklist_p">3</p>
    </td>
  </tr>
</table>

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

What is the best way to ensure that a component remains the highest layer on a react-leaflet map?

I am encountering an issue where the table on my page only shows for a brief second when I refresh the page, and then it disappears. The Map Component being used is a react-leaflet map. I would like to have a component always displayed on top of the map wi ...

Oh no! An operational error occurred while trying to access the page "/1" because it seems like the column

I recently started working with Django and I'm trying to figure out how to display all comments related to a specific listing on an online auction site. Can anyone help me find a solution for this? Models.py class Listing(models.Model): title = m ...

Is it possible to utilize a .css file as the origin with @font-face?

Received a shortened path to a Gotham font... https://cloud.typography.com/[path shortened]/css/fonts.css Attempting to use it in a @font-face definition but facing issues with the src format: @font-face { font-family: 'Gotham'; src: url(" ...

Animate the sliding of divs using the JavaScript animation function

I've designed some boxes that function similar to notifications, but now I want to smoothly slide them in from the left instead of just fading in. I know that I need to use .animate rather than .fadeIn to achieve this effect. The code snippet I&apos ...

Struggling to connect CSS to HTML on Github Pages

I'm new to using Github, and I noticed that when I open the website, my HTML code is displaying without the associated CSS. Here is a snippet of my HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

What is the method for incorporating opacity into the background color CSS attribute using a Fluent UI color?

Currently, my challenge involves applying opacity to a background color sourced from the fluent UI library, which utilizes Design Tokens. Typically, I would add opacity to a background color like this: background-color: "rgba(255, 255, 255, 0.5)" However ...

"I'm facing an issue with aligning elements in my ReactJS application using CSS Flexbox. Despite setting up a flexbox layout, I am unable to

Despite setting up a flexbox to align my elements, I am struggling with vertical centering on my page. I have made sure to use a container for the page and set brute size with viewport units. Here is my sandbox: https://codesandbox.io/s/rlk3j68pmq. Belo ...

What is the best way to showcase an image that is being retrieved from PHP using ajax?

I need to show the image that is being received from PHP via ajax. I can display the name <span id="pic_name">Pic name here</span> but how can I display the image as <img src="images/pic/picname" /> //alert(a); $.ajax({ ...

Tips for preventing the automatic insertion of tbody tag by Firefox?

My webpage is being rendered client-side using XSL and XML sent by the server. I'm encountering a problem with Firefox adding an implicit tbody tag. The issue arises because my XSL generates certain tbody tags based on certain conditions. However, Fi ...

Is there a way to use JQuery to make one button trigger distinct actions in two different divs?

For instance: Press a button - one div flies off the screen while another div flies in. Press the button again - Same div flies out, other div returns. I'm completely new to Javascript/JQuery so any assistance would be highly appreciated! Thank you ...

I need to display 5 columns in a parent component, each with its own unique icon. How can I conditionally render them in a React component?

Creating a parent component to reuse multiple times can be very useful. In my case, I have included 5 different icons in each instance of the component, all taken from hero icons. I have set up an object with unique ids for each child component, but I am ...

"Ensure only one checkbox is selected at a time by unchecking the previous

Hi, I'm facing two issues with the code below. The first problem is that when I select checkbox number 3, it automatically selects number 2 as well. I only want this to happen if I manually check it (similar to checkbox number 2). The second issue i ...

Encountering issues with accessing the clientWidth and clientHeight references of the DOM in Vue

Issue with 'clientWidth' and 'clientHeight' properties on Vue and Element types. <div class="invoice-step-detail" id="invoice" ref="invoice"> @Component({ name: 'CreateInvoice', co ...

Arranging pictures in both vertical and horizontal alignment (CSS)

I've been attempting various methods to solve this issue, but none have proven successful. My goal is quite simple: align images both horizontally and vertically in a manner that fills empty spaces with photos. Similar to the layout here: The challe ...

There is a complete absence of text appearing on the html page when Angular is

Currently, I am in the process of learning Angular during my internship. As part of the requirements, I have been tasked with developing a client-server application using Angular as the frontend framework and Spring as the backend solution. Within the proj ...

What is the material-ui component that mirrors the functionality of <input type="color"><datalist>?

I'm just starting out with javascript, react, and Material-UI, so my question (along with the code sample) might show my lack of experience. Within a Material-UI TableCell (not a form), I have the following code: <input type="color" name ...

What is the best way to apply a semi-transparent background to my navigation bar, while maintaining a blue background across my entire page?

Currently, I have a background set for my website along with a navigation bar that displays my name and additional information. I am looking to make the background of this navigation bar semi-transparent so that it is possible to see through it. I tried ...

Does ng-bind have the ability to function with input elements too?

My mind was spinning as I tried to figure out why my <input ng-bind="x.a * x.b" tabindex="-1" readonly/> expression wasn't functioning. The use of ng-model was not an option due to the fact that the product is not an L-value, so I made the swi ...

The content of btn-id element in Angular is showing as undefined

I have a JavaScript file located at sample/scripts/sample.js and there are 8 HTML files in the directory sample/src/templates/. My goal is to select a button on one of the HTML files. When I tried using angular.elemnt(btn-id).html(), I received an 'un ...

After the initial submission, the Bootstrap placeholder for the Select Option is only displayed

I'm attempting to create a placeholder for my dropdown with multiple options using Angular and Bootstrap. However, it seems like I may be doing something incorrectly. I created an option for a placeholder such as please select and placed it at the top ...