【问题标题】:The position of progress dots are not aligning properly when width is changing宽度变化时进度点的位置没有正确对齐
【发布时间】:2020-11-21 10:50:12
【问题描述】:

我们正在尝试显示连接 7 点线的进度条。但是填充进度条线时进度条点没有正确对齐。

.progress-bar {
  position: relative;
  display: inline-block;
  height: 40px;
  width: 630px;
  background: linear-gradient(to right, #8fe4bf 99.9%, transparent 99.9%), radial-gradient(50px circle at 50%, #8fe4bf 10%, transparent 0%);
  background-position: 0% 50%, 50% 50%;
  background-size: 100% 3px, 80px 70px;
  /* 5px is the thickness of the bar, 50px is 1/8th of the height */
  background-repeat: no-repeat, repeat-x;
}

.progress-now {
  position: absolute;
  height: 100%;
  background: linear-gradient(to right, #00b164 99.9%, transparent 99.9%), radial-gradient(50px circle at 50% 50%, #00b164 10%, transparent 0%);
  background-position: 0% 50%, 50% 50%;
  background-size: 100% 3px, 80px 50px;
  background-repeat: no-repeat, repeat-x;
  z-index: 1;
  width: 60%;
}
<div class="progress-bar">
  <div class="progress-now" id="progress-now" role="progressnow">

  </div>
</div>


<div class="progress-container">
  <div class="progress-bar">
    <div class="progress-now" id="progress-now" role="progressnow">

    </div>
  </div>
</div>

这是填充这样的东西,没有填充适当的位置,我们怎么能这样做。我们已经为我们的代码推荐了Progress bar made of solid line, with dots as steps。请添加一些建议,以便更改宽度不会影响线上点的位置。谢谢。

【问题讨论】:

    标签: html css progress-bar css-shapes


    【解决方案1】:

    换一种方式,考虑background-clip,如下所示:

    .progress-bar {
      position: relative;
      height: 40px;
      background: 
        linear-gradient(#8fe4bf 0 0) center no-repeat, 
        radial-gradient(circle 5px, #8fe4bf 98%, transparent);
      background-size: 100% 3px, 80px 100%;
    }
    
    .progress-bar::before {
      content:"";
      position: absolute;
      top:0;
      left:0;
      right:0;
      bottom:0;
      /* for simplicity I am using the same background 
       and applying a filter to get a different coloration */
      background: inherit;
      filter:brightness(0.7);
      padding-right:calc(100% - var(--p,20%));  /* this will control the progress*/
      background-clip:content-box; /* this will do the magic by clipping the background*/
    }
    <div class="progress-bar"></div>
    <div class="progress-bar" style="--p:50%"></div>
    <div class="progress-bar" style="--p:80%"></div>
    <div class="progress-bar" style="--p:100%"></div>

    要有固定的圈数:

    .progress-bar {
      position: relative;
      height: 40px;
      background: 
        linear-gradient(#8fe4bf 0 0) center no-repeat, 
        radial-gradient(circle 5px, #8fe4bf 98%, transparent);
      background-size: 100% 3px, calc(100%/var(--n,5)) 100%;
    }
    
    .progress-bar::before {
      content:"";
      position: absolute;
      top:0;
      left:0;
      right:0;
      bottom:0;
      /* for simplicity I am using the same background 
       and applying a filter to get a different coloration */
      background: inherit;
      filter:brightness(0.7);
      padding-right:calc(100% - var(--p,20%));  /* this will control the progress*/
      background-clip:content-box; /* this will do the magic by clipping the background*/
    }
    <div class="progress-bar"></div>
    <div class="progress-bar" style="--p:50%;--n:10"></div>
    <div class="progress-bar" style="--p:80%;--n:3"></div>
    <div class="progress-bar" style="--p:100%;--n:8"></div>

    【讨论】:

      猜你喜欢
      • 2018-12-07
      • 2020-05-27
      • 2012-05-12
      • 2015-05-09
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多