先上效果图
<!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;
}