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

求助:无法实现白灰配色的目标CSS进度条,求排查现有代码问题

Fixing Your White-Gray CSS Progress Bar

Let's break down the issues in your current code first, then walk through how to get that clean white-gray animated progress bar you're aiming for:

Key Issues in the Original Code

  • The .bar class has unnecessary padding (especially padding-bottom: 60px and horizontal paddings) that pushes the progress bar out of place and distorts its layout.
  • The .animate class is added to the container but never defined in your CSS, so the animation trigger is effectively missing.
  • The progress bar container itself doesn't have a distinct "background track" to contrast with the filled progress part, which is likely making it look off from your expected design.

Corrected Code with White-Gray Styling

Here's a refined version that fixes those problems and gives you a crisp white-gray animated progress bar:

<!DOCTYPE html>
<html>
<head>
<style>
/* Base progress bar container (the gray track) */
.bar {
  box-sizing: border-box; /* Ensures padding doesn't add to total width */
  height: 20px;
  width: 80%; /* Adjust width as needed */
  margin: 50px auto; /* Centers the bar and adds vertical space */
  background-color: #e0e0e0; /* Light gray track */
  border-radius: 20px; /* Rounded corners for the track */
  overflow: hidden; /* Clips the animated fill to the track's rounded edges */
}

/* Filled progress portion */
.bar .progress-fill {
  display: block;
  height: 100%;
  width: 75%; /* Adjust this to set progress percentage */
  background-color: #ffffff; /* White fill */
  position: relative;
  overflow: hidden;
}

/* Animated diagonal stripe effect */
.bar .progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background-size: 50px 50px;
  background-image: linear-gradient(
    -45deg,
    rgba(128, 128, 128, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(128, 128, 128, 0.2) 50%,
    rgba(128, 128, 128, 0.2) 75%,
    transparent 75%,
    transparent
  );
  animation: move 2s linear infinite;
}

/* Animation keyframes for the stripe movement */
@keyframes move {
  0% { background-position: 0 0; }
  100% { background-position: 50px 50px; }
}
</style>
</head>
<body>
<div class="bar">
  <span class="progress-fill"></span>
</div>
</body>
</html>

What Changed & Why

  • Container Styling: We set a light gray background for .bar to act as the progress track, added overflow: hidden to make sure the rounded corners apply to the fill, and used border-box sizing to avoid layout surprises.
  • Progress Fill: Swapped the fill color to pure white (#ffffff) for that sharp white-gray contrast, and gave it a clear class name for better readability.
  • Animation Adjustment: Changed the stripe color to a subtle gray (rgba(128,128,128,0.2)) so it blends naturally with the white fill while still creating that animated "loading" effect.
  • Cleaner Layout: Removed unnecessary paddings from the container and centered it with margin: 50px auto for a polished, balanced look.

Customization Tips

  • Adjust width on .progress-fill to change how much of the bar is filled (e.g., width: 50% for half progress).
  • Tweak #e0e0e0 (track color) or #ffffff (fill color) to match your exact white-gray palette.
  • Modify the animation duration (currently 2s) to make the stripes move faster or slower.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 06:52:41