Show progress in half whether using css

enter image description here

Something like below:

enter image description here

My Less currently looks like below.

    /*progressbar*/
.progressbar {
    margin-bottom: 30px;
    margin-top: 10px;
    counter-reset: step;
    clear: both;
}

.progressbar li {
    font-size: 12px;
    width: 24%;
    float: left;
    position: relative;
    text-align: center;

    &:before {
    content: counter(step);
    counter-increment: step;
    width: 25px;
    line-height: 13px;
    display: block;
    font-size: 12px;
    color: transparent;
    border: 6px solid #ececec ;
    background: #27ae60 ;
    border-radius: 19px;
    margin: 0 auto 4px;
    }

    &:after {
    content: '';
    width: 85%;
    height: 3px;
    background: #B9B9B9;
    position: absolute;
    left: -42%;
    top: 10px;
    z-index: 0;
   }

   &:first-child:after {
    content: none; 
  }
}

.progress-payment li {
    width: 50%;
}

.progressbar li.active{
    &:after, &:before {      
    background: @success-btn;
    color: @success-btn;
    }
}

HTML

<ul class="progressbar">
    <li class="active">Order Placed</li>
    <li>Shipped</li>
    <li>Completed</li>
    <li>Settled</li>
</ul>

Please, help

+4
source share
2 answers

You can do this using the background linear-gradientfor the pseudo-element that the panel creates. A gradient of one and a half with the finished color for the first half and the pending color for the rest.

/*progressbar*/

.progressbar {
  margin-bottom: 30px;
  margin-top: 10px;
  counter-reset: step;
  clear: both;
  list-style: none;
}
.progressbar li {
  font-size: 12px;
  width: 24%;
  float: left;
  position: relative;
  text-align: center;
}
.progressbar li:before {
  content: counter(step);
  counter-increment: step;
  width: 25px;
  line-height: 25px;
  display: block;
  font-size: 12px;
  color: transparent;
  border: 6px solid #ececec;
  background: #27ae60;
  border-radius: 19px;
  margin: 0 auto 4px;
}
.progressbar li:after {
  content: '';
  width: 85%;
  height: 3px;
  background: #B9B9B9;
  position: absolute;
  left: -42%;
  top: 17px;
  z-index: -1;
}
.progressbar li:first-child:after {
  content: none;
}
.progress-payment li {
  width: 50%;
}
.progressbar li.active:after,
.progressbar li.active:before {
  background: #27ae60;
  color: white;
}

.progressbar li.complete:after {
  background: #27ae60;
}
.progressbar li.half-complete:after {
  background: linear-gradient(to right, #27ae60 50%, #B9B9B9 50%);
  color: white;
}
<ul class="progressbar">
  <li class="complete">Order Placed</li>
  <li class="complete">Shipped</li>
  <li class="active">Completed</li>
  <li class="half-complete">Settled</li>
</ul>
Run codeHide result

If you want a slightly curved half fill for the progress bar, you can use it radial-gradientfor the background, as in the snippet below.

/*progressbar*/

.progressbar {
  margin-bottom: 30px;
  margin-top: 10px;
  counter-reset: step;
  clear: both;
  list-style: none;
}
.progressbar li {
  font-size: 12px;
  width: 24%;
  float: left;
  position: relative;
  text-align: center;
}
.progressbar li:before {
  content: counter(step);
  counter-increment: step;
  width: 25px;
  line-height: 25px;
  display: block;
  font-size: 12px;
  color: transparent;
  border: 6px solid #ececec;
  background: #27ae60;
  border-radius: 19px;
  margin: 0 auto 4px;
}
.progressbar li:after {
  content: '';
  width: 85%;
  height: 3px;
  background: #B9B9B9;
  position: absolute;
  left: -42%;
  top: 17px;
  z-index: -1;
}
.progressbar li:first-child:after {
  content: none;
}
.progress-payment li {
  width: 50%;
}
.progressbar li.active:after,
.progressbar li.active:before {
  background: #27ae60;
  color: white;
}

.progressbar li.complete:after {
  background: #27ae60;
}
.progressbar li.half-complete:after {
  background: radial-gradient(50% 300% at 25% 50%, #27ae60 50%, #B9B9B9 40%);
  color: white;
}
<ul class="progressbar">
  <li class="complete">Order Placed</li>
  <li class="complete">Shipped</li>
  <li class="active">Completed</li>
  <li class="half-complete">Settled</li>
</ul>
Run codeHide result

.. , - , (IE10 +).

+9

animation .

. ul, .

, . , 0 100% 1 4, 1 2, 2 3 ..

:

ul .

.progressbar::after {
  content: '';
  width: 68%;
  height: 3px;
  background: #B9B9B9;
  position: absolute;
  left: 17%;
  top: 17px;
  z-index: -2;
}

::after 0 . ( :, ).

, , , , .

, . ? scale 1 .

.progressbar li.half-complete:after {
  transform: scaleX(0);
  color: white;
  animation: fill 100ms linear forwards;
  background-color: #27ae60;
}

:

@keyframes fill {
  to {
    transform: scaleX(1);
  }
}

:

/*progressbar*/

.progressbar {
  margin-bottom: 30px;
  margin-top: 10px;
  counter-reset: step;
  clear: both;
  list-style: none;
  position: relative;
}
.progressbar li {
  font-size: 12px;
  width: 24%;
  float: left;
  position: relative;
  text-align: center;
}
.progressbar li:before {
  content: counter(step);
  counter-increment: step;
  width: 25px;
  line-height: 25px;
  display: block;
  font-size: 12px;
  color: transparent;
  border: 6px solid #ececec;
  background: #27ae60;
  border-radius: 19px;
  margin: 0 auto 4px;
}
.progressbar li:after {
  content: '';
  width: 85%;
  height: 3px;
  position: absolute;
  left: -42%;
  top: 17px;
  z-index: -1;
}
.progressbar::after {
  content: '';
  width: 68%;
  height: 3px;
  background: #B9B9B9;
  position: absolute;
  left: 17%;
  top: 17px;
  z-index: -2;
}
.progressbar li:first-child:after {
  content: none;
}
.progress-payment li {
  width: 50%;
}
.progressbar li.active:after,
.progressbar li.active:before {
  background: #27ae60;
  color: white;
}
.progressbar li.half-complete:before {
  color: white;
}
.progressbar li.complete:after {
  background: #27ae60;
}
.progressbar li.half-complete:after {
  transform: scaleX(0);
  color: white;
  animation: fill 3s linear forwards;
  background-color: #27ae60;
}
@keyframes fill {
  to {
    transform: scaleX(1);
  }
}
<ul class="progressbar">
  <li class="complete">Order Placed</li>
  <li class="complete">Shipped</li>
  <li class="active">Completed</li>
  <li class="half-complete">Settled</li>
</ul>
Hide result

, , , , 50%.

, , , animation-delay, , , .

transform-origin: left , animation-delay:

/*progressbar*/

.progressbar {
  margin-bottom: 30px;
  margin-top: 10px;
  counter-reset: step;
  clear: both;
  list-style: none;
  position: relative;
}
.progressbar li {
  font-size: 12px;
  width: 24%;
  float: left;
  position: relative;
  text-align: center;
}
.progressbar li:before {
  content: counter(step);
  counter-increment: step;
  width: 25px;
  line-height: 25px;
  display: block;
  font-size: 12px;
  color: transparent;
  border: 6px solid #ececec;
  background: #27ae60;
  border-radius: 19px;
  margin: 0 auto 4px;
}
.progressbar li:after {
  content: '';
  width: 85%;
  height: 3px;
  position: absolute;
  left: -42%;
  top: 17px;
  z-index: -1;
}
.progressbar::after {
  content: '';
  width: 68%;
  height: 3px;
  background: #B9B9B9;
  position: absolute;
  left: 17%;
  top: 17px;
  z-index: -2;
}
.progressbar li:first-child:after {
  content: none;
}
.progress-payment li {
  width: 50%;
}
.progressbar li.active:after,
.progressbar li.active:before {
  background: #27ae60;
  color: white;
}
.progressbar li.half-complete:before {
  color: white;
}
.progressbar li.complete:after {
  background: #27ae60;
}
.progressbar li.half-complete:after {
  transform: scaleX(0);
  color: white;
  animation: fill 3s linear forwards;
  transform-origin: left;
  background-color: #27ae60;
}
@keyframes fill {
  to {
    transform: scaleX(1);
  }
}
<ul class="progressbar">
  <li class="complete">Order Placed</li>
  <li class="complete">Shipped</li>
  <li class="active">Completed</li>
  <li class="half-complete">Settled</li>
</ul>
Hide result

animation-delay :

/*progressbar*/

.progressbar {
  margin-bottom: 30px;
  margin-top: 10px;
  counter-reset: step;
  clear: both;
  list-style: none;
  position: relative;
}
.progressbar li {
  font-size: 12px;
  width: 24%;
  float: left;
  position: relative;
  text-align: center;
}
.progressbar li:before {
  content: counter(step);
  counter-increment: step;
  width: 25px;
  line-height: 25px;
  display: block;
  font-size: 12px;
  color: transparent;
  border: 6px solid #ececec;
  background: #27ae60;
  border-radius: 19px;
  margin: 0 auto 4px;
}
.progressbar li:after {
  content: '';
  width: 85%;
  height: 3px;
  position: absolute;
  left: -42%;
  top: 17px;
  z-index: -1;
}
.progressbar::after {
  content: '';
  width: 68%;
  height: 3px;
  background: #B9B9B9;
  position: absolute;
  left: 17%;
  top: 17px;
  z-index: -2;
}
.progressbar li:first-child:after {
  content: none;
}
.progress-payment li {
  width: 50%;
}
.progressbar li.active:after,
.progressbar li.active:before {
  background: #27ae60;
  color: white;
}
.progressbar li.half-complete:before {
  color: white;
}
.progressbar li.complete:after {
  background: #27ae60;
}
.progressbar li.half-complete:after {
  transform: scaleX(0);
  color: white;
  animation: fill 3s linear forwards;
  transform-origin: left;
  animation-delay: -1.5s;
  background-color: #27ae60;
}
@keyframes fill {
  to {
    transform: scaleX(1);
  }
}
<ul class="progressbar">
  <li class="complete">Order Placed</li>
  <li class="complete">Shipped</li>
  <li class="active">Completed</li>
  <li class="half-complete">Settled</li>
</ul>
Hide result

- 3s, , 50%, ., .

animation-play-state: paused; .

/*progressbar*/

.progressbar {
  margin-bottom: 30px;
  margin-top: 10px;
  counter-reset: step;
  clear: both;
  list-style: none;
  position: relative;
}
.progressbar li {
  font-size: 12px;
  width: 24%;
  float: left;
  position: relative;
  text-align: center;
}
.progressbar li:before {
  content: counter(step);
  counter-increment: step;
  width: 25px;
  line-height: 25px;
  display: block;
  font-size: 12px;
  color: transparent;
  border: 6px solid #ececec;
  background: #27ae60;
  border-radius: 19px;
  margin: 0 auto 4px;
}
.progressbar li:after {
  content: '';
  width: 85%;
  height: 3px;
  position: absolute;
  left: -42%;
  top: 17px;
  z-index: -1;
}
.progressbar::after {
  content: '';
  width: 68%;
  height: 3px;
  background: #B9B9B9;
  position: absolute;
  left: 17%;
  top: 17px;
  z-index: -2;
}
.progressbar li:first-child:after {
  content: none;
}
.progress-payment li {
  width: 50%;
}
.progressbar li.active:after,
.progressbar li.active:before {
  background: #27ae60;
  color: white;
}
.progressbar li.half-complete:before {
  color: white;
}
.progressbar li.complete:after {
  background: #27ae60;
}
.progressbar li.half-complete:after {
  transform: scaleX(0);
  color: white;
  animation: fill 3s linear forwards;
  transform-origin: left;
  animation-delay: -1.5s;
  animation-play-state: paused;
  background-color: #27ae60;
}
@keyframes fill {
  to {
    transform: scaleX(1);
  }
}
<ul class="progressbar">
  <li class="complete">Order Placed</li>
  <li class="complete">Shipped</li>
  <li class="active">Completed</li>
  <li class="half-complete">Settled</li>
</ul>
Hide result

, javascript, , :

.progressbar li.half-complete:after {
  transform: scaleX(0);
  color: white;
  animation: fill 100ms linear forwards; /* Use an easier value to represent percentages in a progress bar*/
  transform-origin: left;
  animation-delay: inherit; /* We inherit the animation-delay from the `li` element, which we can easily manipulate with javascript*/
  animation-play-state: paused;
  background-color: #27ae60;
}

:

var progress = document.getElementById("progress");

var progressBarLastItem = document.querySelector(".progressbar li:last-child");

progress.addEventListener("change", function() {
  progressBarLastItem.style.animationDelay = "-" + this.value + "ms";
});
/*progressbar*/

.progressbar {
  margin-bottom: 30px;
  margin-top: 10px;
  counter-reset: step;
  clear: both;
  list-style: none;
  position: relative;
}
.progressbar li {
  font-size: 12px;
  width: 24%;
  float: left;
  position: relative;
  text-align: center;
}
.progressbar li:before {
  content: counter(step);
  counter-increment: step;
  width: 25px;
  line-height: 25px;
  display: block;
  font-size: 12px;
  color: transparent;
  border: 6px solid #ececec;
  background: #27ae60;
  border-radius: 19px;
  margin: 0 auto 4px;
}
.progressbar li:after {
  content: '';
  width: 85%;
  height: 3px;
  position: absolute;
  left: -42%;
  top: 17px;
  z-index: -1;
}
.progressbar::after {
  content: '';
  width: 68%;
  height: 3px;
  background: #B9B9B9;
  position: absolute;
  left: 17%;
  top: 17px;
  z-index: -2;
}
.progressbar li:first-child:after {
  content: none;
}
.progress-payment li {
  width: 50%;
}
.progressbar li.active:after,
.progressbar li.active:before {
  background: #27ae60;
  color: white;
}
.progressbar li.half-complete:before {
  color: white;
}
.progressbar li.complete:after {
  background: #27ae60;
}
.progressbar li.half-complete:after {
  transform: scaleX(0);
  color: white;
  animation: fill 100ms linear forwards;
  transform-origin: left;
  animation-delay: inherit;
  animation-play-state: paused;
  background-color: #27ae60;
}
@keyframes fill {
  to {
    transform: scaleX(1);
  }
}
<ul class="progressbar">
  <li class="complete">Order Placed</li>
  <li class="complete">Shipped</li>
  <li class="active">Completed</li>
  <li class="half-complete">Settled</li>
</ul>

<input id="progress" type="range" min="0" max="100">
Hide result
0

Source: https://habr.com/ru/post/1658163/


All Articles