【发布时间】:2022-06-11 04:53:55
【问题描述】:
我一直在制作一个显示三种步骤的自定义进度条:done、busy 和 todo 步骤。基本的 html ul li 是基于 flexbox 的,可以在其中添加或取出项目,而不会破坏布局的完整性。
我想要左右延伸的步骤,但是如果不破坏项目的宽度就无法实现。 所有台阶的宽度应相等。 当前的设计工作(并且必须继续工作)只需一、二、三、四或五个步骤。
我希望整个进度条按比例拉伸并完全填充黄色区域。
最终的预期结果应如下所示:
这里,第一个和最后一个项目符号应该接触黄色背景的末端,所有项目符号应该在文本单词上方居中。
可以有两种变化:1)子弹之间的距离相等。 2)项目符号间距取决于文本单词的长度。两者都可以,以包含最少的代码为准。
总之,答案应该是:
- 去掉进度条左右两边未使用的黄色空间
- 在均匀分布所有项目符号及其文本的同时
- 所有项目符号应保持在文本上方的中心
- 当两个、三个、四个和五个 li 项目填充无序列表时保持工作。
演示
https://jsfiddle.net/9s48naw0/
body{
background: lightblue;
width: auto;
padding: 50px;
}
a{text-decoration: none}
.progress {
display: flex;
background: yellow;
width: auto;
}
.progress>li {
flex: 1;
}
.progress>li, .progress>li a{
list-style: none;
text-align: center;
width: auto;
padding: 0;
margin: 0;
position: relative;
text-overflow: ellipsis;
color: lightgrey;
display: block;
}
.progress>li .circle {
border-radius: 50%;
width: 24px;
height: 24px;
background: lightgrey;
display: block;
margin: 0 auto .5em;
}
.progress>li .circle:after,
.progress>li .circle:before {
display: block;
position: absolute;
top: 10px;
width: 100%;
height: 4px;
content: '';
background: lightgrey;
}
.progress>li :before {left: 0}
.progress>li :after {right: 0}
.progress>li:first-child .circle:after,
.progress>li:first-child .circle:before {
width: 50%;
margin-left: 50%
}
.progress>li:last-child .circle:after,
.progress>li:last-child .circle:before {
width: 50%;
margin-right: 50%
}
.progress>li.done .circle,
.progress>li.done .circle:after,
.progress>li.done .circle:before {background: green}
.progress>li.done,
.progress>li.done a{color: green}
.progress>li.busy .circle,
.progress>li.busy .circle:after,
.progress>li.busy .circle:before {background: violet}
.progress>li.busy,
.progress>li.busy a{color: violet}
<ul class="progress">
<li class="done">
<a href="#" title="More about the First Step">
<span class="circle"></span>
Step1</a>
</li>
<li class="done">
<a href="#" title="Afterwards the Second Step">
<span class="circle"></span>
Step2</a>
</li>
<li class="busy">
<a href="#" title="This about the current active Step">
<span class="circle"></span>
Step3</a>
</li>
<li>
<a href="#" title="Future Next Step">
<span class="circle"></span>
Step4</a>
</li>
<li>
<a href="#" title="And the Final Step">
<span class="circle"></span>
Step5</a>
</li>
</ul>
【问题讨论】:
标签: css layout flexbox css-selectors progress-bar