gpt4 book ai didi

javascript - 如何实现一个简单的react多步控制

转载 作者:行者123 更新时间:2023-12-04 14:53:37 24 4
gpt4 key购买 nike

我是 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
}

但是,在前面的示例中,没有选择第一个“步骤”,而是选择了第二个“步骤”,如下图所示(似乎我遇到了某种“偏离一个问题”):

enter image description here

如能提供解决此问题的任何帮助,我们将不胜感激!

编辑:出于对原作者的尊重,我改编的例子可以在这里找到:https://steemit.com/utopian-io/@alfarisi94/how-to-make-step-progress-bar-only-using-css

最佳答案

+符号选择器选择紧跟在指定元素之后的元素,因此 li.selected + li:before目标 <li>Weight Index</li>因为它就在 li 之后类名 .selected .

以下将修复它:

.progressbar li.selected:after {
background: #3aac5d;
}

.progressbar li.selected:before {
border-color: #3aac5d;
background: #3aac5d;
color: white;
}

const ACProgressSteps = () => {
return (
<div className='container'>
<ul className='progressbar nobullets'>
<li className='selected'>Aircraft Type</li>
<li>Weight Index</li>
<li>Airport Times</li>
<li>Documents</li>
<li>Tada</li>
</ul>
</div>
);
};

ReactDOM.render(<ACProgressSteps />, document.getElementById('root'));
.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:after {
background: #3aac5d;
}

.progressbar li.selected:before {
border-color: #3aac5d;
background: #3aac5d;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="root"></div>

关于javascript - 如何实现一个简单的react多步控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68596749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com