CSS 进度步进器在第一步中不起作用



我按照教程制作了以下进度步进器。当它设置为活动时,它不会显示步骤 1。其他步骤在设置为活动时有效。有人可以帮我了解 CSS 中需要更改的内容以允许步骤 1 显示为活动状态吗?

我意识到我可以选择一个不同的步进器,但我喜欢这个,因为它只是 CSS,我想从这个问题中学习。

.container {
width: 100%;
position: absolute;
z-index: 1;
}
.progressbar li {
float: left;
width: 20%;
position: relative;
text-align: center;
list-style: none;
}
.progressbar {
counter-reset: step;
}
.progressbar li:before {
content: counter(step);
counter-increment: step;
width: 30px;
height: 30px;
border: 2px solid #bebebe;
display: block;
margin: 0 auto 10px auto;
border-radius: 50%;
line-height: 27px;
background: white;
color: #bebebe;
text-align: center;
font-weight: bold;
}
.progressbar li:after {
content: '';
position: absolute;
width: 100%;
height: 3px;
background: #979797;
top: 15px;
left: -50%;
z-index: -1;
}
.progressbar li:first-child:after {
content: none;
}
.progressbar li.active+li:after {
background: #3aac5d;
}
.progressbar li.active+li:before {
border-color: #3aac5d;
background: #3aac5d;
color: white
}
<div class="container">
<ul class="progressbar">
<li class="active">Step 1</li>
<li>Step 2</li>
<li>Step 3</li>
<li>Step 4</li>
<li>Step 5</li>
</ul>
</div>

如果您在完成后将active类添加到每个<li>,那么简单地从选择器中删除+li似乎有效:

小提琴:https://jsfiddle.net/fwpadbty/

最新更新