Unique CSS-created chronological schedule with alternating design

I am looking to customize my CSS timeline by removing the first line and changing the color of each individual circle. How can I achieve both of these modifications?

I attempted to add a class called .not_complete to one of the timeline containers, but it did not alter the circle's color as intended.

/* The actual timeline (the vertical ruler) */
.timeline {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  padding-bottom: 5em;
}

/* The actual timeline (the vertical ruler) */
.timeline:before {
  content: '';
  position: absolute;
  width: 0px;
  background-color: #fff;
  top: auto;
  bottom: 0;
  left: 50%;
  margin-left: -3px;
}

.timeline::after {
  content: '';
  position: absolute;
  width: 4px;
  background-color: #e3e3e3;
  top: 0;
  bottom: 0;
  left: 50%;
  margin-left: -3px;
}

/* Container around content */
.container {
  padding: 10px 40px;
  position: relative;
  background-color: inherit;
  width: 50%;
}

/* The circles on the timeline */
.container::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  right: -5px;
  background-color: #e3e3e3;
  top: 15px;
  border-radius: 50%;
  z-index: 1;
}

.container::after .not_complete {
  background-color: #e3e3e3 !important;
}

/* Place the container to the left */
.left {
  left: 0;
}

/* Place the container to the right */
.right {
  left: 50%;
}

/* Fix the circle for containers on the right side */
.right::after {
  left: -7px;
}

/* The actual content */
.content {
  padding: 2px 3px;
  position: relative;
  border-radius: 6px;
}
<div class="timeline">
  <div class="container left not_complete">
    <div class="content">
      <p>
        <img src="assets/img/therapist1.jpg" style="border-radius: 0.5em;border-top-left-radius: 120px; border-bottom-right-radius: 120px">
      </p>
      <h5 style="color:#999;font-style: 0.5em"> DAY 1 </h5>
      <div> Test Timeline Step 1</div>
    </div>
  </div>
</div>

Answer №1

The selector provided is incorrect:

.containerx::after .not_complete {

This would target the child of the ::after pseudo-element. The correct selector should be:

.containerx.not_complete::after {

The updated selector targets any element's ::after pseudo-element with the classes containerx and not_complete. Please replace your code with the following:

.containerx.not_complete::after {
  background-color: #e3e3e3 !important;
}

We hope this resolves your issue.

Complete Snippet

/* The actual timeline (the vertical ruler) */
.timelinex {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  padding-bottom: 5em;
}

/* The actual timeline (the vertical ruler) */
.timelinex:before {
  content: '';
  position: absolute;
  width: 0px;
  background-color: #fff;
  top: auto;
  bottom: 0;
  left: 50%;
  margin-left: -3px;
}


.timelinex::after {
  content: '';
  position: absolute;
  width: 4px;
  background-color: #e3e3e3;
  top: 0;
  bottom: 0;
  left: 50%;
  margin-left: -3px;
}

/* Container around content */
.containerx {
  padding: 10px 40px;
  position: relative;
  background-color: inherit;
  width: 50%;
}

/* The circles on the timeline */
.containerx::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  right: -5px;
  background-color: #e3e3e3;
  top: 15px;
  border-radius: 50%;
  z-index: 1;
}

.containerx.not_complete::after {
  background-color: #e3e3e3 !important;
}


/* Place the container to the left */
.leftx {
  left: 0;
}

/* Place the container to the right */
.rightx {
  left: 50%;
}


/* Fix the circle for containers on the right side */
.rightx::after {
  left: -7px;
}

/* The actual content */
.contentx {
  padding: 2px 3px;
  position: relative;
  border-radius: 6px;
}
<div class="timelinex" >
  <div class="containerx leftx not_complete">
    <div class="contentx">
      <p><img src="assets/img/therapist1.jpg" style="border-radius: 0.5em;border-top-left-radius: 120px; border-bottom-right-radius: 120px"></p>
      <h5 style="color:#999;font-style: 0.5em"> DAY 1 </h5>
      <div> Test Timeline Step 1</div>
    </div>
  </div>
</div>

Update: For Even / Odd Styling and First Child.

To create alternating styles for odd and even items, you can use the :nth-child() selector. Here's an example where odd elements are blue and even elements are red:

li {
  display: block;
  width: 200px;
  padding: 10px;
  color: #fff;
}
li:nth-child(odd) {
  background: #00f;
}
li:nth-child(even) {
  background: #f00;
}
li:first-child {
  background: #000;
  font-weight: bold;
}
<ul>
  <li>First Child</li>
  <li>Even</li>
  <li>Odd</li>
  <li>Even</li>
  <li>Odd</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

How can I display data saved from step 2 in a multi-step form with 4 steps, when I return from step 3 to step 2?

Let's consider this scenario: Imagine the user is at step 2 and types their name into <input type="text" class="form-control input-xl" ngModel name="firstName"> They proceed to step 3 but then decide to return to step 2. The information entere ...

Is it possible to share deep links with just a hashtag?

I am currently developing a web application and I want to include social media buttons such as Facebook Like. I have tried using the HTML code/API provided by Facebook, AddThis, Shareaholic, ShareThis, but none of them seem to properly handle my deep link ...

Missing ghost image appears when you drag and drop the file

New to JavaScript... As a rookie in coding, I often get interesting requests from my partner who is a kindergarten teacher. Recently, she asked me to create a "Function Machine" for her classroom activities. With some trial and error, I managed to put tog ...

Displaying incorrect text format on a TextView using Html.fromHtml()

Within my application, there is a string that represents a mathematical expression: String s = "log<small><sub>(log<small><sub>(log<small><sub>3<small><sup>2</sup></small></sub></small&g ...

The styled components can create identical CSS classes with varying conditions

Below are the CSS styles I am currently using: import styled, { css } from "styled-components"; const H4 = css` font-family: "Futura"; font-style: normal; font-weight: 500; font-size: 20px; line-height: 140%; color: #3a786a ...

Attempting to implement a disappearing effect upon submission with the use of JavaScript

I am currently working on implementing a disappearing form feature for a small web application. The idea is that once the initial form is submitted, it will be replaced by a new form. While my current code somewhat works, it only lasts for a brief moment b ...

Adjust Font Size inside Circular Shape using CSS/jQuery

I have been searching for different libraries that can resize text based on the size of a container. However, my container is circular and I am facing difficulty in preventing the text from overflowing beyond the border. Below you will find a Fiddle conta ...

Preserve the iframe src value in the dropdown menu even after the page is refreshed

I am trying to figure out how to prevent the iframe src from changing when I refresh the page, unless the user manually changes it using the dropdown menu with JavaScript. Can someone help me with this? <div class="row"> <div class="span9"> ...

Center-align the table element

I've been struggling to center align this table element, specifically the one containing the square, but nothing seems to be working. Can anyone lend a hand in fixing this issue? <table> <tbody> <tr> <td>TURKEY - SU ...

A comprehensive guide on how to find keywords within an array and then proceed to make all text within the parent div tag stand

I am currently looking for a webpage that displays a list of products based on keywords from an array. Once it detects any word in the array, it highlights it with a red background - everything is working smoothly so far. However, I now wish for the script ...

How can we filter the input type file browse window to display only image files?

I'm trying to figure out how to filter the window popup so that it only shows image files when I click on the input type file. <input type="file" /> Any help would be greatly appreciated as I have been struggling to find a solution for this. ...

The webpage freezes when attempting to run jQuery with Selenium

I'm currently facing an issue where my selenium script hangs the webpage whenever I try to find an element using jQuery. The script doesn't execute and a pop up appears in the browser with the message "A script on this page may be busy, or it may ...

Head styles for tinyMCE

When viewing the tinyMCE example on the official website using Firefox, you may notice the editor blinking. This issue seems to only occur in Firefox, possibly due to external CSS files for the editor. I am considering adding all CSS rules directly into th ...

Is there a way for me to access the response from the PHP file I'm calling with Ajax?

I am just starting to explore ajax and jquery, and I recently found a code online that I'm tweaking for my own use. However, I am struggling with how to handle responses from PHP in this context. The current setup involves ajax POSTing to a php page ...

What is the reason behind Svelte not scoping the tag under a class, but instead using individual tag.class to style a component?

It is common practice to scope CSS styles for components like this: .my-component-01 h1 { ... } .my-component-01 h2 { ... } However, Svelte takes a different approach by applying the styles directly to the tags: h1.svelte-hlsza1{color:orange} h2.svelte- ...

What is the best way to adjust image size based on different screen sizes while ensuring the buttons at the top remain responsive

How can I make the image and image select and delete buttons responsive? I am looking to eliminate the gap after the delete button. Any suggestions are welcomed. <div class="container mt-0"> <div class="row"> ...

Restrict the child's height to the remaining space within the parent container

I'm attempting to divide the viewport's height between two divs. In the top div, there is a small div followed by a larger div that should scroll if it doesn't fit within the remaining space of the parent div. Below is the structure of my HT ...

Excessive Width Issue Caused by Bootstrap 4 Navbar Items

Having trouble with my Bootstrap 4 Navbar menu implementation. When I add more items, they overflow the container instead of floating correctly. Any CSS suggestions to temporarily fix this issue? <!DOCTYPE html> <html lang="en"> <head> ...

Is there a way to access the value of a variable within a loop inside a function and store it in a global variable?

I am struggling to retrieve the value of a variable after it has passed through a loop. I attempted to make it a global variable, but its value remains unchanged. Is there any way to achieve this? Below is my code snippet where I am attempting to access t ...

Creating a Visual Presentation with Background Image Transition in HTML, CSS, and JavaScript

Seeking assistance in setting up a basic background image slideshow on my website. I have been unable to locate a suitable tutorial online, so I'm reaching out here for guidance. HTML: <body> <h3>Welcome!</h1> <p>Lorem i ...