【发布时间】:2021-10-06 08:10:28
【问题描述】:
我是 CSS 的新手,并尝试基于一些现有代码实现多步 React 控件(目前这些步骤是静态的,一旦我发现了我的问题,我就会让事情变得动态):
import styles from "./ProgressSteps.module.css";
const ACProgressSteps = () =>{
return(
<div className={styles.container}>
<ul className={`${styles.progressbar} ${styles.nobullets}`}>
<li className={styles.selected}>Aircraft Type</li>
<li>Weight Index</li>
<li>Airport Times</li>
<li>Documents</li>
<li>Tada</li>
</ul>
</div>
)}
活动步骤由{styles.selected} 标识(之前应用此样式的所有步骤也应标记为绿色)。对应的样式如下(我在自己的控件中导入):
.container{
width: 100%;
position: absolute;
z-index: 1;
}
.progressbar{
counter-reset: step;
}
ul.nobullets {
list-style-type: none; /* Remove bullets */
padding: 0; /* Remove padding */
margin: 0; /* Remove margins */
}
.progressbar li{
float: left;
width: 20%;
position: relative;
text-align: center;
}
.progressbar li:before{
counter-increment: step;
content:counter(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.selected + li:after{
background: #3aac5d;
}
.progressbar li.selected + li:before{
border-color: #3aac5d;
background: #3aac5d;
color: white
}
但是,在前面的示例中,没有选择第一个“步骤”,而是选择了第二个步骤,如下图所示(似乎我遇到了某种“问题”):
任何解决此问题的帮助将不胜感激!
编辑:为了感谢原作者,我改编的例子可以在这里找到:https://steemit.com/utopian-io/@alfarisi94/how-to-make-step-progress-bar-only-using-css
【问题讨论】:
标签: css reactjs css-selectors