[英]CSS Stepper - LI After overlaying LI Before
I'm using some code found at codepen with a Stepper Control.我正在使用在 codepen 上找到的一些带有步进控件的代码。 I'm not vey skilled with CSS and I'm having an issue not presented in codepen, so I assume is another CSS class defined in a very long stylesheet that is shared with other team mates.
我对 CSS 不是很熟练,而且我遇到了 codepen 中没有出现的问题,所以我假设是另一个 CSS class 在与其他队友共享的非常长的样式表中定义。 The problem I tried to fix is that the line defined in the class.progressbar li:after remains above the class.progressbar li:before, that defines the circles.
我试图解决的问题是 class.progressbar li:after 中定义的行仍然高于 class.progressbar li:before,它定义了圆圈。
li:after initially came with a z-index: -1 and li:before didn't have the z-index property, but the lines didn't appear, they were hidden behind a div, so I had to modify it and that's what is shown in the snippet. li:after 最初带有一个 z-index: -1 和 li:before 没有 z-index 属性,但是线条没有出现,它们隐藏在一个 div 后面,所以我不得不修改它,那就是片段中显示的内容。 Although this z-index: -1 works in the snippet, is not working where I want to be implemented.
尽管此 z-index: -1 在代码段中有效,但在我想要实施的地方不起作用。
This first image shows the result of the CSS Stepper, taken directly from codepen to my page with z-index:-1第一张图片显示了 CSS Stepper 的结果,直接从 codepen 带到我的页面,z-index:-1
This other image shows the result after trying to adjust the z-index property:另一张图片显示了尝试调整 z-index 属性后的结果:
This is the desired output:这是所需的 output:
Here's the snippet:这是片段:
.container { width: 600px; margin: 100px auto; z-index: -1; }.progressbar li { list-style-type: none; width: 25%; float: left; font-size: 12px; position: relative; text-align: center; text-transform: uppercase; color: #666666; }.progressbar li:after { width: 100%; height: 2px; content: ''; position: absolute; background-color: #666666; top: 15px; left: -50%; display: block; z-index: 1; }.progressbar li:before { width: 30px; height: 30px; content: ''; line-height: 30px; border: 2px solid #666666; display: block; text-align: center; margin: 0 auto 10px auto; border-radius: 50%; background-color: white; z-index: 999999; }.progressbar li:first-child:after { content: none; }.progressbar li.active { color: green; }.progressbar li.active:before { border-color: #55b776; }.progressbar li.active + li:after { background-color: #55b776; }
<div class="container"> <ul class="progressbar"> <li >aaaaaa</li> <li class="active">bbbbbbbbbt</li> <li>cccccccc</li> <li>ddddddddd</li> </ul> </div>
¿Could I get some help to solve this problem, or where could I start looking? ¿我可以得到一些帮助来解决这个问题,或者我可以从哪里开始寻找?
I think it's all said, but please, if I left something, I'll try to complete the post.我想都说完了,但拜托,如果我留下了什么,我会尽力完成这篇文章。
Thanks in advance,提前致谢,
You just need to reduce the z-index
of .progressbar li:after
like this (no other changes required ):您只需要像这样减少
.progressbar li:after
的z-index
(不需要其他更改):
.progressbar li:after {
width: 100%;
height: 2px;
content: '';
position: absolute;
background-color: #666666;
top: 15px;
left: -50%;
display: block;
z-index: -999999;
}
You can see it working below:你可以看到它在下面工作:
.container { width: 600px; margin: 100px auto; z-index: -1; }.progressbar li { list-style-type: none; width: 25%; float: left; font-size: 12px; position: relative; text-align: center; text-transform: uppercase; color: #666666; }.progressbar li:after { width: 100%; height: 2px; content: ''; position: absolute; background-color: #666666; top: 15px; left: -50%; display: block; z-index: -999999; }.progressbar li:before { width: 30px; height: 30px; content: ''; line-height: 30px; border: 2px solid #666666; display: block; text-align: center; margin: 0 auto 10px auto; border-radius: 50%; background-color: white; z-index: 999999; }.progressbar li:first-child:after { content: none; }.progressbar li.active { color: green; }.progressbar li.active:before { border-color: #55b776; }.progressbar li.active+li:after { background-color: #55b776; }
<div class="container"> <ul class="progressbar"> <li>aaaaaa</li> <li class="active">bbbbbbbbbt</li> <li>cccccccc</li> <li>ddddddddd</li> </ul> </div>
You must give the element a position
-value in order to use z-index
.您必须为元素提供
position
值才能使用z-index
。 Just apply position: relative;
只需申请
position: relative;
to the .progressbar li:before
-element:到
.progressbar li:before
元素:
.container { width: 600px; margin: 100px auto; }.progressbar li { list-style-type: none; width: 25%; float: left; font-size: 12px; position: relative; text-align: center; text-transform: uppercase; color: #666666; }.progressbar li:after { width: 100%; height: 2px; content: ''; position: absolute; background-color: #666666; top: 15px; left: -50%; display: block; }.progressbar li:before { width: 30px; height: 30px; content: ''; line-height: 30px; border: 2px solid #666666; display: block; text-align: center; margin: 0 auto 10px auto; border-radius: 50%; background-color: white; position: relative; z-index: 1; }.progressbar li:first-child:after { content: none; }.progressbar li.active { color: green; }.progressbar li.active:before { border-color: #55b776; }.progressbar li.active+li:after { background-color: #55b776; }
<div class="container"> <ul class="progressbar"> <li>aaaaaa</li> <li class="active">bbbbbbbbbt</li> <li>cccccccc</li> <li>ddddddddd</li> </ul> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.