html - CSS BUG:箭头进度条高度不匹配
问题描述
我正在尝试实现带箭头的进度条,但遇到了 CSS 错误。当我增加内容的高度时,附加箭头的高度不会增加。尝试运行代码 spinnet,您将了解我面临的错误。错误基于 CSS 和三角形/箭头进度条内容高度
ol.steps {
list-style: none;
margin: 0;
padding: 0;
overflow: hidden;
font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', 'DejaVu Sans', 'Bitstream Vera Sans', 'Liberation Sans', Verdana, 'Verdana Ref', sans-serif;
font-size: 13px;
line-height: 20px;
font-weight: bold;
counter-reset: li;
}
ol.steps li {
list-style-image: none;
list-style-type: none;
margin-left: 0;
text-align: center;
color: #3a3a3a;
background: #dae4eb;
position: relative;
margin-left: 43px;
}
ol.steps li:after {
position: absolute;
top: 30%;
left: 100%;
content: " ";
height: 0;
width: 0;
pointer-events: none;
border: solid transparent;
border-left-color: #dae4eb;
border-width: 19px;
margin-top: -19px;
}
ol.steps li:first-child {
margin-left: 0;
}
ol.steps li:first-child span {
padding: 9px;
}
ol.steps li:first-child span:after {
border: none;
}
ol.steps li:last-child:after {
border-width: 0;
}
ol.steps li span {
display: block;
padding: 9px 28px 9px 9px;
}
ol.steps li span:after {
position: absolute;
top: 50%;
right: 100%;
content: " ";
height: 0;
width: 0;
pointer-events: none;
border: solid #dae4eb;
border-left-color: transparent;
border-width: 19px;
margin-top: -19px;
}
ol.steps li span:before {
content: counter(li) " ";
counter-increment: li;
}
ol.steps>li {
float: left;
}
ol.steps li.current {
height: 60px;
color: #fff;
background: #0078b4;
}
ol.steps li.current:after {
border-left-color: #0078b4;
}
ol.steps li.current span:after {
border-color: #7b7b7b;
border-left-color: transparent;
}
ol.steps li.step1 {
z-index: 9;
}
ol.steps li.step2 {
z-index: 8;
}
ol.steps li.step3 {
z-index: 7;
}
ol.steps li.step4 {
z-index: 6;
}
ol.steps li.step5 {
z-index: 5;
}
ol.steps li.step6 {
z-index: 4;
}
ol.steps li.step7 {
z-index: 3;
}
ol.steps li.step8 {
z-index: 2;
}
ol.steps li.step9 {
z-index: 1;
}
ol.steps li.step10 {
z-index: 0;
}
<ol class="steps">
<li class="step1 current"><span><br>Submitted</span></li>
<li class="step2"><span><br>.</span></li>
<li class="step3"><span><br>.</span></li>
<li class="step4"><span><br>.</span></li>
<li class="step5"><span><br>.</span></li>
</ol>
错误图像:在此处输入图像描述
我尝试了许多 CSS 调整,但成功匹配了高度所需的结果:所需的结果
解决方案
我修改了几行代码并绘制了具有相同高度的进度箭头并展平了第一个列表和最后一个列表。
*, *:before, *:after{
box-sizing: border-box;
}
body{
padding: 0;
margin: 0;
width: 100%;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
ol.steps {
list-style: none;
margin: 0;
padding: 0;
overflow: hidden;
font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', 'DejaVu Sans', 'Bitstream Vera Sans', 'Liberation Sans', Verdana, 'Verdana Ref', sans-serif;
font-size: 13px;
line-height: 20px;
font-weight: bold;
counter-reset: li;
}
ol.steps li {
list-style-image: none;
list-style-type: none;
margin-left: 0;
text-align: center;
color: #3a3a3a;
background: #dae4eb;
position: relative;
margin-left: 2px;
padding-right: 0px;
padding-left: 60px;
transition: 300ms;
float: left;
}
ol.steps li:before, ol.steps li:after {
position: absolute;
content: " ";
height: 60px;
width: 60px;
background-color: #dae4eb;
z-index: 10;
top: 0;
transform: rotate(-45deg);
right: -18px;
transition: 300ms;
}
ol.steps li:before{
right: auto;
left: -40px;
background-color: #fff;
pointer-events: none;
z-index: 1;
}
ol.steps li:first-child {
margin-left: 0;
background-color: red;
padding-left: 30px;
}
ol.steps li:first-child:before{
display: none;
}
ol.steps li span {
display: block;
position: relative;
padding: 9px 28px 9px 9px;
z-index: 50;
pointer-events: none;
}
ol.steps li span:before {
content: counter(li);
counter-increment: li;
display: block;
}
ol.steps li.current, ol.steps li:hover{
color: #fff;
background: #0078b4;
cursor: pointer;
}
ol.steps li.current:after, ol.steps li:hover:after {
background-color: #0078b4
}
<ol class="steps">
<li class="step1 current"><span>Begin</span></li>
<li class="step2"><span>ABC</span></li>
<li class="step3"><span>CDE</span></li>
<li class="step4"><span>EFG</span></li>
</ol>
推荐阅读
- regex - 正则表达式在字符串或数字之前获取值
- python - 我们可以在 python 中使用 pandas 集成 3D 图形,它会根据 excel 的变化自动更新吗?
- flutter - Flutter 1.22.6 - url_launcher - 发送 HTML 电子邮件
- reactjs - 帆布已经在使用中。必须先销毁 ID 为“0”的图表,然后才能重新使用画布。聊天.JS
- sql-server - 如何在我的 SSIS 包中实施此特定操作?
- android - 关于Android工具链的“颤振医生”错误
- nuxt.js - 如何将光滑的轮播添加到 Nuxt
- python - Python unittest:写,读,比较不起作用
- angular - 如何替换打字稿中字符串之间的空格?
- view - 如何从 SQL 视图创建棱镜模型