You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅用CSS实现底部向上填充的双DIV进度条并集成到Shopify

仅用CSS实现底部向上填充的进度条(适配Shopify自定义HTML板块)

下面是实现你需要的双进度条效果的完整代码,直接复制到Shopify的自定义HTML板块即可使用,包含外部标签和内部标签两种样式:

<div class="progress-bar-container">
  <div class="progress-bar-item">
    <span class="label external-label">95% 回收材料</span>
    <div class="progress-bar">
      <div class="fill" style="--progress: 95%"></div>
    </div>
  </div>
  <div class="progress-bar-item">
    <div class="progress-bar">
      <span class="label internal-label">100% 可回收</span>
      <div class="fill" style="--progress: 100%"></div>
    </div>
  </div>
</div>

<style>
.progress-bar-container {
  max-width: 600px;
  margin: 2rem auto;
  gap: 1.5rem;
  display: flex;
  flex-direction: column;
  padding: 0 1rem;
}

.progress-bar-item {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.progress-bar {
  flex: 1;
  height: 24px;
  border-radius: 12px;
  background-color: #f0f0f0;
  overflow: hidden;
  position: relative;
}

.progress-bar .fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--progress);
  background-color: #34d399;
  animation: fillFromBottom 1.5s ease-out forwards;
}

@keyframes fillFromBottom {
  0% {
    height: 0;
  }
  100% {
    height: var(--progress);
  }
}

.label {
  font-size: 0.95rem;
  font-weight: 500;
  font-family: Arial, sans-serif;
}

.external-label {
  min-width: 130px;
  text-align: right;
  color: #333;
}

.internal-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  z-index: 2;
  pointer-events: none;
}
</style>

关键细节说明

  • 进度值通过CSS变量--progress直接控制,修改style="--progress: XX%"即可调整填充比例,无需改动CSS代码。
  • 内部标签通过position:absolute和z-index:2确保显示在填充层上方,pointer-events:none避免干扰板块的交互逻辑。
  • 动画使用ease-out曲线让填充结尾更自然,时长(1.5s)可根据需求调整。
  • 容器设置了响应式布局,适配移动端和桌面端显示。

Shopify集成步骤

  1. 登录Shopify后台,进入目标页面/产品的编辑界面(如首页、产品详情页)。
  2. 在板块区域点击「添加板块」,选择「自定义HTML」板块。
  3. 将上述完整代码粘贴到自定义HTML的编辑框中。
  4. 根据你的店铺风格调整颜色、字体大小、进度值等参数。
  5. 预览确认效果后,点击保存即可完成集成。

内容的提问来源于stack exchange,提问作者Matthieu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 08:40:18