4

Problem Definition

I have a div tag that has a border-radius of 50% to display a circle. Here is the HTML code below:

.pie-wrapper {
  height: 2.5em;
  width: 2.5em;
  margin: 15px auto;
  position: relative;
}

.pie-wrapper--solid {
  border-radius: 50%;
  overflow: hidden;
}

.pie-wrapper--solid:before {
  border-radius: 0 100% 100% 0 / 50%;
  content: "";
  display: block;
  height: 100%;
  margin-left: 50%;
  transform-origin: left;
}

.pie-wrapper--solid.progress-88 {
  border: 5px ridge blue;
  background: linear-gradient(to right, springgreen 50%, #ff0000 50%);
}

.pie-wrapper--solid.progress-88:before {
  background: springgreen;
  transform: rotate(0deg);
  animation-name: change-color;
  animation-duration: 5s;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  animation-iteration-count: 1;
  animation-direction: normal;
}


/* Keyframes */

@keyframes change-color {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(180deg);
  }
}
<div class="pie-wrapper pie-wrapper--solid progress-88">
</div>

What I Tried

I applied a linear-gradient to create a background with two colors. I went ahead to try different linear-gradient types such as to left, to bottom, to top etc. This didn't achieve the purpose.

The Expectation

The animation rotates to 180 degrees as expected but any number above rotate(180deg) will not cover the expected portions of the pie. The goal is for the red part to fully cover the green part in the animation keyframes at rotate(360deg) i.e a complete red circle. I would also like the animation to rotate anti-clockwise, this can be achieved by placing a negative value inside the rotate function.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    [Maybe this question helps](https://stackoverflow.com/questions/14222138/css-progress-circle) – Apodemus Mar 31 '23 at 07:51
  • @Apodemus The problem is not the rotation itself but the ::before pseudo-class that does not rotate past 180 degrees. – Tawanda Andrew Msengezi Mar 31 '23 at 09:19
  • To test what I'm trying to ask, remove the animation and change the value of transform: rotate(0deg) on the .pie-wrapper--solid.progress-88:before selector and use 90deg, 180deg, 270deg, and 360deg while viewing the output on each interval. – Tawanda Andrew Msengezi Mar 31 '23 at 09:30

0 Answers0