html - 如何修复此进度条上的分层?
问题描述
我已经建立了这个进度条,但我需要沿途放置进度标记,但我试图把它放在两个现有层之间。
我尝试了一些 z-index 工作,但我真的不明白。
#progress {
background: grey;
border-radius: 13px;
height: 20px;
width: 100%;
padding: 3px;
}
.label-line {
float: right;
background: white;
height:30px;
width:2px;
margin-left: 2px;
}
.bar-step {
position:absolute;
margin-top:-10px;
font-size:12px;
}
#progress::after {
content: '';
display: block;
background: blue;
width: 50%; /* THIS IS THE ACTUAL PROGRESS */
height: 100%;
border-radius: 9px;
}
<div id="progress">
<div class="bar-step" style="left: 30%">
<div class="label-line"></div>
</div>
</div>
白线位于酒吧的最前面。
解决方案
将position: relative
和添加z-index
到进度条伪元素 ( ::after
) 将其放置在标记线上方。
#progress {
background: grey;
border-radius: 13px;
height: 20px;
width: 100%;
padding: 3px;
}
.label-line {
float: right;
background: white;
height:30px;
width:2px;
margin-left: 2px;
}
.bar-step {
position:absolute;
margin-top:-10px;
font-size:12px;
}
#progress::after {
position: relative; /* this is needed for z-index to work */
z-index: 3;
content: '';
display: block;
background: blue;
width: 50%; /* THIS IS THE ACTUAL PROGRESS */
height: 100%;
border-radius: 9px;
}
<div id="progress">
<div class="bar-step" style="left: 30%">
<div class="label-line"></div>
</div>
</div>
推荐阅读
- javascript - 在 expess.js TypeError 中发布请求错误:无法读取未定义的属性“fullName”
- php - 如何在控制器的函数中设置类属性并在其他函数中使用它?
- typescript - nuxt 启动时预加载数据到 store
- python - 无法绘制熊猫系列的直方图
- python - Python脚本中的Listagg函数问题
- c# - 等待客户端重新连接服务器一段时间 - Socket io Unity Express 服务器
- google-cloud-platform - Google IoT Core 如何实现 MQTT 负载平衡
- graphql - 如何在 ExceptionFilter [NestJS] 中找出 Query 或 Mutation 返回类型
- r - R S4 插槽,更改内容,而不是属性
- node.js - Chokidar - 文件观察器