CSS Progress Stepper 第一步不工作
CSS Progress Stepper not working on first step
我按照教程制作了以下进度步进器。当它设置为活动时,它不会显示步骤 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
class 添加到每个 <li>
,那么只需从选择器中删除 +li
似乎就可以了:
Fiddle: https://jsfiddle.net/fwpadbty/
我按照教程制作了以下进度步进器。当它设置为活动时,它不会显示步骤 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
class 添加到每个 <li>
,那么只需从选择器中删除 +li
似乎就可以了:
Fiddle: https://jsfiddle.net/fwpadbty/