前端项目共读!50个项目50天之02:进度步骤条的HTML、CSS和JavaScript实现
warning:
这篇文章距离上次修改已过190天,其中的内容可能已经有所变动。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>进度步骤条</title>
<style>
.progress-container {
width: 100%;
margin: 40px 0;
overflow: hidden;
counter-reset: step;
}
.step {
float: left;
position: relative;
text-align: center;
width: 10%;
border-right: 1px solid #eee;
counter-increment: step;
}
.step:before {
content: counter(step);
display: block;
margin: 0 auto 4px;
background-color: #fff;
border-radius: 50%;
width: 32px;
height: 32px;
border: 1px solid #ddd;
box-shadow: 0 0 4px rgba(0,0,0,0.2);
}
.step:last-child {
border-right: none;
}
.step-label {
display: block;
font-size: 13px;
color: #666;
margin-top: 8px;
}
</style>
</head>
<body>
<div class="progress-container">
<div class="step">
<div class="step-label">步骤一</div>
</div>
<div class="step">
<div class="step-label">步骤二</div>
</div>
<!-- 更多步骤... -->
</div>
</body>
</html>
这个简单的HTML代码展示了如何使用CSS伪元素和CSS计数器来创建一个进度步骤条。每个.step
都会有一个带有step-label
的数字标记,这个数字代表了进度。通过CSS样式,我们可以自定义这个进度条的外观,并且可以通过在.progress-container
内添加更多的.step
元素来增加步骤数。
评论已关闭