【发布时间】:2020-09-06 10:29:15
【问题描述】:
我按照教程制作了以下进度步进器。当它设置为活动时,它不会显示第 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>
【问题讨论】:
-
您正在选择紧跟在
<li class="active">之后的li。阅读有关相邻兄弟选择器的更多信息:developer.mozilla.org/en-US/docs/Web/CSS/…。此外,提供所用教程的链接可能会改善您的问题。
标签: css progress-bar stepper