外圈进度条

如何解决外圈进度条

我试图让进度条的外圈与其后面的黑圈对齐。我已经调整了多个元素的高度和宽度,但没有运气。

我试过了:

  • 调整SVG的宽度
  • 调整圆的高度和宽度

这是我试图让它看起来的方式:

enter image description here

这是它目前的样子:

enter image description here

请帮助解释我应该调整什么?

#progress-bar {
  position: absolute;
  left: 50%;
  top: 55%;
  transform: translate(-51%,-50%);
  width: 40%;
}

.container {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: space-around;
}

.container .card {
  position: relative;
  width: 400px;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 400px;
  border-radius: 4px;
  text-align: center;
  overflow: hidden;
  transition: 0.5s;
}

.container .card:before {
  content: '';
  position: absolute;
  top: 0;
  left: -50%;
  width: 100%;
  height: 100%;
  background: rgba(255,255,0.03);
  pointer-events: none;
  z-index: 1;
}

.percent {
  position: relative;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  Box-shadow: inset 0 0 50px #000;
  background: #222;
  z-index: 1000;
}

.percent .number {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
}

.percent .number h2 {
  color: #777;
  font-weight: 700;
  font-size: 40px;
  transition: 0.5s;
}

.card:hover .percent .number h2 {
  color: #fff;
  font-size: 60px;
}

.percent .number h2 span {
  font-size: 24px;
  color: #777;
  transition: 0.5s;
}

.card:hover .percent .number h2 span {
  color: #fff;
}

.text {
  position: relative;
  color: #777;
  margin-top: 20px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: 0.5s;
}

svg {
  position: relative;
  width: 150px;
  height: 150px;
  z-index: 1000;
}

svg circle {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: #191919;
  stroke-width: 10;
  stroke-linecap: round;
  transform: translate(5px,5px);
}

svg circle:nth-child(2) {
  stroke-dasharray: 440;
  stroke-dashoffset: 440;
}

.card:nth-child(1) svg circle:nth-child(2) {
  stroke-dashoffset: calc(
    440 - (440 * 90) / 100
  ); /* use to adjust progress bar */
  stroke: #00ff43;
}
  <div class="container">
              <div class="card">
                <div class="Box">
                  <div class="percent">
                    <svg>
                      <circle cx="70" cy="70" r="70"></circle>
                      <circle cx="70" cy="70" r="70"></circle>
                    </svg>
                    <div class="number">
                      <h2>90<span>%</span></h2>
                    </div>
                  </div>
                  <h2 class="text">Html</h2>
                </div>
              </div>
            </div>

解决方法

<style>
    svg {
      position: relative;
      width: 200px;
      height: 200px;
      z-index: 1000;
    }
    svg circle{
        fill: none;
        stroke-width: 10;
        stroke-linecap: round;
        stroke-dasharray: 1000;
    }
    svg circle:nth-child(2){
        stroke: #f00;
        stroke-dashoffset: 1000;
        animation: dash 2s linear forwards;
    }
    svg circle:nth-child(1){
        stroke-dashoffset: 0;
        stroke: #000;
    }
    @keyframes dash {
      to {
        stroke-dashoffset: 0;
      }
    }
</style>
<body>
<svg>
    <circle cx="50%" cy="50%" r="40%"></circle>
    <circle cx="50%" cy="50%" r="40%"></circle>
</svg>
</body>

将值 cxcy 设置为 50% 并将 r 设置为 40%
上面的简单动画应该显示 stroke-dashoffsetstroke-dashoffset: 0; 之间的动画 stroke-dashoffset: 1000;
应该提到的是,0 到 1000 之间的值不是线性的。这意味着 stroke-dashoffset: 100; 不是圆的 10%。
您可以在代码中实现此示例,并以 % 为单位调整 svg 的宽度和高度。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?