HTML做多颜色进度条

先上效果图
在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
  <title>多颜色进度条</title>
</head>
<body>
  <div style="width: 300px; height: 20px; background-color: #eee; border-radius: 10px; overflow: hidden;">
    <div style="height: 100%;">
      <div style="width: 30%; background-color: #00ffce; height: 100%; float: left;"></div>
      <div style="width: 20%; background-color: #ffc02f; height: 100%; float: left;"></div>
      <div style="width: 40%; background-color: #fff2cf; height: 100%; float: left;"></div>
      <div style="width: 10%; background-color: #fde0e2; height: 100%; float: left;"></div>
    </div>
  </div>
</body>
</html>

首次改进后
底层背景颜色在这里插入图片描述

用于表层进度的颜色在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
  <title>多层多颜色进度条</title>
</head>
<body>
  <div style="width: 300px; height: 20px; background-color: #eee; border-radius: 10px; overflow: hidden;">
    <div style="height: 100%; position: relative;">
      <!-- 第一层进度条 -->
      <div style="width: 20%; background-color: #d4ffec; height: 100%; position: absolute;"></div>
      <div style="width: 60%; background-color: #fff2cf; height: 100%; position: absolute; left: 20%;"></div>
      <div style="width: 20%; background-color: #fde0e2; height: 100%; position: absolute; left: 80%;"></div>
      
      <!-- 第二层进度条 -->
      <div style="width: 20%; background-color: #00ffce; height: 100%; position: absolute;"></div>
      <div style="width: 60%; background-color: #ffc02f; height: 100%; position: absolute; left: 20%;"></div>
      <div style="width: 20%; background-color: #ff5733; height: 100%; position: absolute; left: 80%;"></div>
    </div>
  </div>
</body>
</html>

二次改进
增加标尺线在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
  <title>多层多颜色进度条</title>
</head>
<body>
  <div style="width: 300px; height: 25px; background-color: #eee; border-radius: 10px; overflow: hidden;">
	<div style="height: 100%; position: relative;">
      <!-- 第一层进度条 -->
      <div style="width: 20%; background-color: #d4ffec; height: 100%; position: absolute;"></div>
      <div style="width: 60%; background-color: #fff2cf; height: 100%; position: absolute; left: 20%;"></div>
      <div style="width: 20%; background-color: #fde0e2; height: 100%; position: absolute; left: 80%;"></div>
      
      <!-- 第二层进度条 -->
      <div style="width: 20%; background-color: #00ffce; height: 100%; position: absolute;"></div>
      <div style="width: 60%; background-color: #ffc02f; height: 100%; position: absolute; left: 20%;"></div>
      <div style="width: 20%; background-color: #ff5733; height: 100%; position: absolute; left: 80%;"></div>
    </div>
    <div style="width: 2px; height: 34px; background-color: transparent; position: absolute; left: 7%; top: 0; margin-top: 4px; border-left: 2px dashed red; z-index: 1;"></div>
    
  </div>
</body>
</html>    

提取css样式后

<!DOCTYPE html>
<html>
<head>
  <title>多层多颜色进度条</title>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
  <div class="progress-container">
    <div class="progress-bar">
      <!-- 第一层进度条 -->
      <div class="progress-layer" style="width: 20%; background-color: #d4ffec;"></div>
      <div class="progress-layer" style="width: 60%; background-color: #fff2cf; left: 20%;"></div>
      <div class="progress-layer" style="width: 20%; background-color: #fde0e2; left: 80%;"></div>
      
      <!-- 第二层进度条 -->
      <div class="progress-layer" style="width: 20%; background-color: #00ffce;"></div>
      <div class="progress-layer" style="width: 60%; background-color: #ffc02f; left: 20%;"></div>
      <div class="progress-layer" style="width: 20%; background-color: #ff5733; left: 80%;"></div>
    </div>
    <div class="dashed-line"></div>
  </div>
</body>
</html>
/* styles.css */
.progress-container {
  width: 300px;
  height: 25px;
  background-color: #eee;
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  position: relative;
}

.progress-layer {
  height: 100%;
  position: absolute;
}

/* 垂直虚线样式 */
.dashed-line {
  width: 2px;
  height: 34px;
  background-color: transparent;
  position: absolute;
  left: 7%;
  top: 0;
  margin-top: 4px;
  border-left: 2px dashed red;
  z-index: 1;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
HTML5进度条颜色可以通过CSS样式来定义和设置。在HTML5中,进度条是通过 <progress> 元素来实现的。可以使用CSS来自定义进度条颜色和样式。 首先,可以使用CSS的伪类选择器来设置进度条颜色。通过伪类选择器 ::-webkit-progress-value 和 ::-moz-progress-bar,可以设置进度条不同部分的颜色。具体可以使用 background-color 属性来设置进度条颜色。 其次,可以使用 CSS 的 ::-moz-progress-bar 和 ::-webkit-progress-bar 伪元素选择器来设置整个进度条的背景颜色。这两个属性可以分别设置在 Firefox 和 Webkit 浏览器中进度条颜色。 以下是一个示例代码,演示了如何使用CSS来设置HTML5进度条颜色: ```html <!DOCTYPE html> <html> <head> <style> /* 设置进度条整体样式 */ ::-moz-progress-bar { background-color: blue; /* Firefox */ } ::-webkit-progress-bar { background-color: blue; /* Webkit浏览器 */ } /* 设置进度条的已完成部分的样式 */ ::-webkit-progress-value { background-color: green; /* Webkit浏览器 */ } ::-moz-progress-value { background-color: green; /* Firefox */ } </style> </head> <body> <!-- 使用 <progress> 元素创建进度条 --> <progress value="80" max="100"></progress> </body> </html> ``` 在上述代码中,<progress> 元素创建了一个进度条,并设置了初始值(value)为80,最大值(max)为100。通过CSS样式设置进度条的整体颜色和已完成部分的颜色。 这样,就可以根据需要自定义HTML5进度条颜色了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gristle_egg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值