HTML CSS Stepper: A Clean and Simple Design

I'm having trouble with a progress bar that I've been working on.

My goal is to have the progress bar change its background color to blue before it's set to the "active" class. However, currently, the change in color only happens after the class is set to "active."

Below is my HTML code:

<ul class="progressBar">
  <li class="active">Processing Order</li>
  <li class="active">Payment Pending</li>
  <li>Payment Received</li>
</ul>

And here is the CSS code:

.progressBar li.active {
  color: dodgerblue;
}
.progressBar li.active:before {
  border-color: dodgerblue;
  background-color: dodgerblue
}
.progressBar li.active + li:after {
  background-color: dodgerblue;
}

Current Result:

https://i.sstatic.net/fC2qd.png

Desired Outcome:

https://i.sstatic.net/He5Qw.png

Here is the link to the code snippet for reference.

Answer №1

Try using .progressBar .active:after rather than

.progressBar li.active + li:after

Explanation about the "+" in CSS

The plus sign (+) is known as the Adjacent sibling combinator in CSS. It is used to select elements that are immediately preceded by a certain element.

.container-progressBar {
    width: 100%
}

.progressBar {
}

.progressBar li {
    list-style-type: none;
    float: left;
    width: 33%;
    position: relative;
    text-align: center;
}

.progressBar li:before {
    content: " ";
    line-height: 30px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    border: 1px solid #ddd;
    display: block;
    text-align: center;
    margin: 0 auto 10px;
    background-color: white
}

.progressBar li:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 4px;
    background-color: #ddd;
    top: 15px;
    left: -50%;
    z-index: -1;
}

.progressBar li:first-child:after {
    content: none;
}

.progressBar li.active {
    color: dodgerblue;
}

.progressBar li.active:before {
    border-color: dodgerblue;
    background-color: dodgerblue
}

.progressBar .active:after {
    background-color: dodgerblue;
}
<div class="row">
  <div class="col-xs-12 col-md-8 offset-md-2 section border">
    <div class="container-progressBar">
      <ul class="progressBar">
        <li class="active">Processing</li>
        <li class="active">Awaiting shipment</li>
        <li>Shipped</li>
      </ul>
    </div>
  </div>
</div>

Answer №2

As per your request, here is an answer that aligns more closely with what you were looking for:

.wrapper-progressBar {
    width: 100%
}

.progressBar {
}

.progressBar li {
    list-style-type: none;
    float: left;
    width: 33%;
    position: relative;
    text-align: center;
}

.progressBar li:before {
    content: " ";
    line-height: 30px;
    border-radius: 50%;
    width: 17px;
    height: 17px;
    border: 1px solid #ddd;
    border-left:none;
    display: block;
    text-align: center;
    margin: 8.5px auto 0px;
    background-color: #eee;
}
.progressBar li:after {
    content: "";
    position: absolute;
    width: 97%;
    height: 5px;
    background-color: #eee;
    border: 1px solid #ddd;
    border-right:none;
    top: 15px;
    left: -50%;
    z-index: -1;
}

.progressBar li:first-child:after {
    content: none;
}

.progressBar li.active {
    color: dodgerblue;
}

.progressBar li.active:before {
    border-color: dodgerblue;
    background-color: dodgerblue
}

.progressBar .active:after {
    background-color: dodgerblue;
}
<div class="row">
  <div class="col-xs-12 col-md-8 offset-md-2 block border">
    <div class="wrapper-progressBar">
      <ul class="progressBar">
        <li class="active">Processing Order</li>
        <li class="active">Waiting for Payment</li>
        <li>Payment Received</li>
      </ul>
    </div>
  </div>
</div>

Answer №3

Consider updating your CSS selector from

.progressBar li.active + li:after
to .progressBar li.active:after

.wrapper-progressBar {
    width: 100%
}

.progressBar {
}

.progressBar li {
    list-style-type: none;
    float: left;
    width: 33%;
    position: relative;
    text-align: center;
}

.progressBar li:before {
    content: " ";
    line-height: 30px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    border: 1px solid #ddd;
    display: block;
    text-align: center;
    margin: 0 auto 10px;
    background-color: white
}

.progressBar li:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 2px;
    background-color: #ddd;
    top: 15px;
    left: -50%;
    z-index: -1;
}

.progressBar li:first-child:after {
    content: none;
}

.progressBar li.active {
    color: dodgerblue;
}

.progressBar li.active:before {
    border-color: dodgerblue;
    background-color: dodgerblue
}

.progressBar li.active:after {
    background-color: dodgerblue;
}
<div class="row">
  <div class="col-xs-12 col-md-8 offset-md-2 block border">
    <div class="wrapper-progressBar">
      <ul class="progressBar">
        <li class="active">Being Processed</li>
        <li class="active">Waiting for payment</li>
        <li>Paid</li>
      </ul>
    </div>
  </div>
</div>

Answer №4

.custom-progressBar {
    width: 100%
}

.progress-bar {
}

.progress-bar-item {
    list-style-type: none;
    float: left;
    width: 33%;
    position: relative;
    text-align: center;
}

.progress-bar-item:before {
    content: " ";
    line-height: 30px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    border: 1px solid #ddd;
    display: block;
    text-align: center;
    margin: 0 auto 10px;
    background-color: white
}

.progress-bar-item:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 2px;
    background-color: #ddd;
    top: 15px;
    left: -50%;
    z-index: -1;
}

.progress-bar-item:first-child:after {
    content: none;
}

.progress-bar-item.active {
    color: dodgerblue;
}

.progress-bar-item.active:before {
    border-color: dodgerblue;
    background-color: dodgerblue;
    content:"\2713";
    color:white;
}

.progress-bar-item.active:after {
    background-color: dodgerblue;

}
<div class="row">
  <div class="col-xs-12 col-md-8 offset-md-2 block border">
    <div class="custom-progressBar">
      <ul class="progress-bar">
        <li class="active">1st Step Completed</li>
        <li class="active">Payment Pending</li>
        <li>Paid</li>
      </ul>
    </div>
  </div>
</div>

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

Finding an element by XPath through identifying text adjacent to the element

Looking for a solution with the given HTML structure below: <tr> <td><input name="Choice" type="radio" value="someValue"></td> <td><a href="">text</a></td> </tr ...

Enclose each set of objects, such as text, within a separate div, except for div elements

Is there a way to wrap each immediate group of objects that are not contained in a div with a wrap class? Input: var $code = 'Lorem Ipsum <p>Foo Bar</p> <div class="myclass"></div> <p>Foo Bar</p> <div clas ...

The parent div isn't properly extending to accommodate the table, and the columns aren't aligning correctly within the table when using CSS flexbox

I have a scenario where I need a table inside a div to take up the entire space of the div, with the second column and its inputs expanding as much as possible to fill the width (i.e. col1+col2 = div width). Due to being nested within another div, absolut ...

A step-by-step guide to implementing Google Analytics Event tracking using PHP

Implementing Google Analytics Events in Javascript can be done using the following code: ga('send', 'event', 'test', 'test','value'); I am trying to incorporate this feature throughout my entire project. ...

What is the best way to centralize the storage of my website's header and footer?

Constantly updating headers and footers requires me to manually transfer the code to each web page every time, which is not the most efficient method. I'm considering using a "header" and "footer" div, and using jQuery's $(document).ready functio ...

display a div beside the anchor element using jQuery

I could really use some assistance. I'm fairly new to jquery and I'm encountering an issue that appears to be quite simple. I apologize if this has been asked before, but I couldn't find the solution I needed. My problem involves having 2 l ...

Obtain the complete source code by using the responseText property of the XMLHttpRequest object

I am looking to retrieve the entire source code of a webpage, such as www.google.com. Currently, I have a PHP file that can copy the source code of a page: <?php echo file_get_contents('http://www.google.com'); ?> Here is my function ...

Adding elements in jQuery can be done by using the `

I am having trouble understanding why my jQuery code is not appending an element to my webpage Below is the code snippet I am using <script> $(document).ready(function() { $(function() { $("#button<?php echo $data[&apos ...

I am struggling to get the pop-up to close using the current code. I suspect that the issue might be related to the variable I was previously using in WordPress. I have made changes but the pop-up

While delving deeper into the realm of Javascript, I encountered a stumbling block with a single popup intended for the main page of a WordPress website I am constructing. Despite my attempts to modify the code's variables, they seem unyielding. Surpr ...

Maximized - Immersive Full Screen Background - Limited to Half the Size?

Looking to incorporate the Supersized Fullscreen background found at Supersized Interested in having the slider appear on the right half of the site with content on the left half. Want the content to move when scrolled while keeping the background station ...

How to Utilize JQuery for Sticky Elements

I am experimenting with a unique twist on the classic Sticky Element concept. Check out for a typical sticky element example. Instead of the traditional sticky behavior, I am looking to have an element initially anchored to the bottom of the user's ...

What is the best way to style the currently selected option element in a select dropdown?

I am trying to change the font color of specific option elements within a select dropdown by adding style="color: #D4D4D4". When I apply this style directly to an option element like <option value="TEST" style="color: #D4D4D4">TEST</option>, it ...

What is the best way to incorporate a CSS transition without any dynamic property changes?

Is there a way to add a transition effect to a header when its size changes without a specified height value in the CSS? The header consists of only text with top and bottom padding, so as the text changes, the height adjusts accordingly. How can I impleme ...

Words next to picture

Can someone help me with aligning different images of varying widths but the same height inline with text next to each image? I tried to do it, but it doesn't look good on responsive screens. Any suggestions on how to fix this? And if there's a b ...

What methods can be used to pause a jQuery function when hovering and resume it when the mouse leaves?

I'm currently working on a jQuery function that operates on the mousemove event. The goal is to have two images - one main image and one shadow image, with the shadow image reflecting movement based on mouse position. While everything is functioning p ...

clicking the table to export it to Excel

Currently, I am facing an issue while working on IE9. The code below is meant to download a HTML table as an excel spreadsheet: <a id="toExcel" onclick="window.open('data:application/vnd.ms-excel,' + document.getElementById('resultsTable ...

Creating a thumbnail with a close button using an image

My code is available at the following link: https://codepen.io/manuchadha/pen/PBKYBJ In this form I have created, I am trying to implement an image upload feature using a file input. The goal is to display a thumbnail of the selected image below the file ...

The CSS counter fails to increment

In this unique example: h3 { font-size: .9em; counter-reset: section; } h4 { font-size: .7em; counter-reset: subsection; } h3:before { counter-increment: section; content: counter(section)" "; } h4:before { counter-increment: subsection 2; ...

Toggle the tooltip to reveal a hidden div by clicking, and then click again to close it

I've been working on implementing a toggle div with a tooltip. The issue I'm facing is that the tooltip initially displays "Click to open", but after opening the toggle, it should change to "Click to close". Can someone assist me in achieving thi ...

Tips and Tricks for Utilizing ngTagsInput for Streamlining Data Filtering

I have a code snippet that helps expand search results, but I'm seeking assistance in refining the filtering process. For instance, I want to add specific tags like "color" and "green" so that only results containing both tags appear, rather than ever ...