简体   繁体   English

Z索引未堆叠

[英]Z-index is not stacking

I have been trying around for so long, and have read a number of articles and I still don't get it! 我已经尝试了很长时间,并且已经阅读了许多文章,但我还是听不懂! I am trying got move that little icon to the left of the header, but for some reason its stacking below the parent element! 我试图将那个小图标移到标题的左侧,但是由于某种原因,它堆叠在父元素下方!

this is my css: 这是我的CSS:

  .step__content { margin-top: 120px; position: relative; div.ui-accordion-header { margin-left: 30px; &:after { content: ''; position: absolute; height: 20px; width: 20px; left: -7px; background-image: url('../images/i.svg'); z-index: 100; } } } 

here is the html: 这是HTML: 在此处输入图片说明

the first :after element is the icon! 第一个:after元素是图标!

here is an image: 这是一张图片:

在此处输入图片说明

I want the icon to be at the left of the header! 我希望图标位于标题的左侧! But as I push it left it goes below? 但是当我向左推时,它会降到下方吗? The complete image of the icon is not visible because half is underneath! 该图标的完整图像不可见,因为下面有一半!

I think what is actually happening is the pseudo element is just going outside of an overflow: hidden; 我认为实际发生的是伪元素刚刚超出overflow: hidden; element... 元件...

This works for me (even if you remove the z-index styles). 这对我有用(即使您删除了z-index样式)。 As you can see the psuedo element is over the text. 如您所见,psuedo元素位于文本上方。 Try changing the :after z-index to -5 and it goes below. 尝试将:after z-index更改为-5,它会低于以下值。

 .step__content { margin-top: 120px; position: relative; } .ui-accordion-header { position: relative; margin-left: 50px; z-index: 1; } .ui-accordion-header:after { content: ''; position: absolute; display: block; height: 30px; width: 30px; margin: auto; top: 0; bottom: 0; left: -20px; background-image: url('https://via.placeholder.com/150'); background-size: cover; background-position: center; z-index: 5; } 
 <div class="step__content"> <div class="ui-accordion-header"> <p>Headers</p> </div> </div> 

I use before pseudo element instead. 我在伪元素之前使用。

  .step__content {
            margin-top: 120px;
            position: relative;

            div.ui-accordion-header {
                margin-left: 30px;

                &::before {
                    content: 'testing';
                    height: 20px;
                    width: 20px;
                    z-index: 100;

                }
            }
        }
<div class="step__content">

<section class="ce_accordionStart ce_accordino block">
  <div id="ui-id-1" class="ui-accordion-header ui-accordion-header-active ui-state-active">

  <span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s">
    Header
  </span>
  </div>
</section>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM