Stepper Pure HTML CSS
Asked Answered
N

4

10

I'm confused about a progress bar that I have created.

I want the progress bar to change its background color to blue after setting the class to “active”. But I want the progress bar to change its background color before the class is set to “active”.

Here is my HTML:

<ul class="progressBar">
  <li class="active">Beong Processed</li>
  <li class="active">Waiting for payment</li>
  <li>Paid</li>
</ul>

…and CSS:

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

The result is this

wrong

I want it to be like this

right

https://jsfiddle.net/dedi_wibisono17/c69e374r/2/

Neutrophil answered 22/8, 2018 at 6:27 Comment(0)
H
15

Use .progressBar .active:after instead of .progressBar li.active + li:after

+ in css

It is Adjacent sibling combinator. It combines two sequences of simple selectors having the same parent and the second one must come IMMEDIATELY after the first.

.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: 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 block border">
    <div class="wrapper-progressBar">
      <ul class="progressBar">
        <li class="active">Beong Processed</li>
        <li class="active">Waiting for payment</li>
        <li>Paid</li>
      </ul>
    </div>
  </div>
</div>
Hon answered 22/8, 2018 at 6:41 Comment(3)
tell me for mor helpAslam
it work, I understand that's you mean. and thank you so much to explain itNeutrophil
happy to help:)Aslam
C
7

According to what you requested, this is more like the answer you asked 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">Beong Processed</li>
        <li class="active">Waiting for payment</li>
        <li>Paid</li>
      </ul>
    </div>
  </div>
</div>
Cy answered 22/8, 2018 at 6:53 Comment(2)
I will suggest to also setting margin and padding to 0 in .progressBar, otherwise the ul is not centered.Slayton
@Slayton I'm sure he can figure out that for himself depending on the usecase.Cy
B
3

Try changing your .progressBar li.active + li:after selector 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">Beong Processed</li>
        <li class="active">Waiting for payment</li>
        <li>Paid</li>
      </ul>
    </div>
  </div>
</div>
Babylonian answered 22/8, 2018 at 6:41 Comment(4)
@MuhammadAliDEV What do you mean "is not working"?Babylonian
it means "line is not displayed".Mclemore
@MuhammadAliDEV The line is displayed when I run the snippet. What browser are you using?Babylonian
i am using Chrome.Mclemore
M
0

.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;
    content:"\2713";
    color:white;
}

.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">1st Step Processed</li>
        <li class="active">Waiting for payment</li>
        <li>Paid</li>
      </ul>
    </div>
  </div>
</div>
Mastoiditis answered 4/4, 2023 at 15:22 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Ivoryivorywhite

© 2022 - 2024 — McMap. All rights reserved.