css 环形百分比图

472 阅读1分钟

主要是分左右2部分,先将left设置成左半圆,right设置成右半圆,其中左右宽高一致,宽是高的一半,

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style type="text/css">
      .container {
        display: flex;
      }

      .left {
        width: 100px;
        height: 200px;
        position: relative;
        overflow: hidden;
      }

      .leftcircle {
        width: 160px;
        height: 160px;
        border: 20px solid rgb(255 255 255);
        position: absolute;
        border-radius: 50%;
        left: 0px;
        top: 0px;
        border-bottom: 20px solid rgb(255, 182, 193, 1);
        border-left: 20px solid rgb(255, 182, 193, 1);
        transform: rotate(45deg);
        animation-name: circle_left;
        animation-duration: 20s;
        animation-timing-function: linear;
        animation-iteration-count: infinite;
      }

      .right {
        width: 100px;
        height: 200px;
        position: relative;
        overflow: hidden;
      }

      .rightcircle {
        width: 160px;
        height: 160px;
        border-radius: 50%;
        border: 20px solid rgb(255 255 255);
        position: absolute;
        border-top: 20px solid rgb(255, 182, 193, 1);
        border-right: 20px solid rgb(255, 182, 193, 1);
        right: 0px;
        top: 0px;
        animation-name: circle_right;
        animation-duration: 20s;
        animation-timing-function: linear;
        animation-iteration-count: infinite;
        transform: rotate(-135deg);
      }

      @keyframes circle_right {
        0% {
          transform: rotate(-135deg);
        }

        50%,
        100% {
          transform: rotate(45deg);
        }
      }
      @keyframes circle_left {
        0%,
        50% {
          transform: rotate(-135deg);
        }

        100% {
          transform: rotate(45deg);
        }
      }
    </style>
  </head>

  <body>
    <!-- <div class="demo"></div> -->
    <!-- <img
      src="./Group 1708test.svg"
      style="width: 195px; position: absolute; padding: 3px"
    /> -->
    <div class="container">
      <div class="left">
        <div class="leftcircle"></div>
      </div>
      <div class="right">
        <div class="rightcircle"></div>
      </div>
    </div>
  </body>
</html>