Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS circle-progress-bar

Tags:

css

I would like to use the progress-bar here at https://bootsnipp.com/snippets/featured/circle-progress-bar, but I don't know how to set less than 50% when you have 2, 3 or more types (each got different percentage) of these on your website, because this code sets right-side of bar for every type u got there and I don't know what to do when I want less than 50% only at 3.

Type of bar:

 .progress .progress-right .progress-bar{
    left: -100%;
    border-top-left-radius: 80px;
    border-bottom-left-radius: 80px;
    border-right: 0;
    -webkit-transform-origin: center right;
    transform-origin: center right;
    animation: loading-1 1.8s linear forwards;
}

+

    @keyframes loading-1{
    0%{
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    100%{
        -webkit-transform: rotate(180deg);
        transform: rotate(180deg);
    }

Could someone help me please ?

like image 747
Marek Cmarko Avatar asked Jun 29 '26 16:06

Marek Cmarko


2 Answers

Using SVG

svg {
  transform: rotate(-90deg);
  stroke-dasharray: 251; /* (2PI * 40px) */
  stroke-dashoffset: 251;
  animation: offsettozero 5s linear forwards;
}

@keyframes offsettozero {
  to {
    stroke-dashoffset: 0;
  }
}
<svg height="100" width="100">
 <circle cx="50" cy="50" r="40" stroke="#428bca" stroke-width="6" fill="#333" />
</svg> 

<!-- VV Click "Run code snippet" for demo -->
like image 71
Chris Gunawardena Avatar answered Jul 02 '26 18:07

Chris Gunawardena


Since the right-side animation is shared among all the progress circles, if you want to make one that is less than 50%, you'll have to override that generic style. Then you won't need a left-side animation.

So your CSS would be something like:

.progress.yourDiv .progress-right .progress-bar {
  animation: yourAnimation 1.8s linear forwards;
}
.progress.yourDiv .progress-left .progress-bar{
  animation: none;
}

Where yourAnimation is the same as the shared right-side rule for .progress .progress-right .progress-bar in the Bootstrap example, except the name is changed.

For an animation to 37.5%, yourAnimation would look like this:

@keyframes yourAnimation{
    0%{
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    100%{
        -webkit-transform: rotate(135deg);
        transform: rotate(135deg);
    }
}

Here's an example, where .yourDiv is .yellow and yourAnimation is loading-3.

.progress {
  width: 150px;
  height: 150px !important;
  float: left;
  line-height: 150px;
  background: none;
  margin: 20px;
  box-shadow: none;
  position: relative;
}
.progress:after {
  content: "";
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 12px solid #fff;
  position: absolute;
  top: 0;
  left: 0;
}
.progress>span {
  width: 50%;
  height: 100%;
  overflow: hidden;
  position: absolute;
  top: 0;
  z-index: 1;
}
.progress .progress-left {
  left: 0;
}
.progress .progress-bar {
  width: 100%;
  height: 100%;
  background: none;
  border-width: 12px;
  border-style: solid;
  position: absolute;
  top: 0;
}
.progress .progress-left .progress-bar {
  left: 100%;
  border-top-right-radius: 80px;
  border-bottom-right-radius: 80px;
  border-left: 0;
  -webkit-transform-origin: center left;
  transform-origin: center left;
}
.progress .progress-right {
  right: 0;
}
.progress .progress-right .progress-bar {
  left: -100%;
  border-top-left-radius: 80px;
  border-bottom-left-radius: 80px;
  border-right: 0;
  -webkit-transform-origin: center right;
  transform-origin: center right;
  animation: loading-1 1.8s linear forwards;
}
.progress .progress-value {
  width: 90%;
  height: 90%;
  border-radius: 50%;
  background: #44484b;
  font-size: 24px;
  color: #fff;
  line-height: 135px;
  text-align: center;
  position: absolute;
  top: 5%;
  left: 5%;
}
.progress.blue .progress-bar {
  border-color: #049dff;
}
.progress.blue .progress-left .progress-bar {
  animation: loading-2 1.5s linear forwards 1.8s;
}
.progress.yellow .progress-bar {
  border-color: #fdba04;
}
.progress.yellow .progress-right .progress-bar {
  animation: loading-3 1.8s linear forwards;
}
.progress.yellow .progress-left .progress-bar {
  animation: none;
}
@keyframes loading-1 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
  }
}
@keyframes loading-2 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(144deg);
    transform: rotate(144deg);
  }
}
@keyframes loading-3 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(135deg);
    transform: rotate(135deg);
  }
}
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>


<div class="progress blue">
  <span class="progress-left">
                    <span class="progress-bar"></span>
  </span>
  <span class="progress-right">
                    <span class="progress-bar"></span>
  </span>
  <div class="progress-value">90%</div>
</div>

<div class="col-md-3 col-sm-6">
  <div class="progress yellow">
    <span class="progress-left">
                    <span class="progress-bar"></span>
    </span>
    <span class="progress-right">
                    <span class="progress-bar"></span>
    </span>
    <div class="progress-value">37.5%</div>
  </div>
</div>
like image 26
cjl750 Avatar answered Jul 02 '26 18:07

cjl750



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!