父元素,子元素和子元素本身的伪元素的Z索引

问题描述 投票:0回答:1

如何使父元素的伪元素的z-index高于子元素的伪元素的z-index,但是子元素本身具有最高的z-index?

我希望红色条纹覆盖灰色矩形,但不覆盖标题本身。

这里是fiddle

 .wrapper {
     position: relative;
      background: #000;
      overflow: hidden;
    }
    .wrapper::after {
      content: "";
        position: absolute;
        width: 650px;
        height: 1500px;
        background: rgb(244,116,31);
    background: -moz-linear-gradient(top,  rgba(244,116,31,1) 0%, rgba(218,14,6,1) 100%);
    background: -webkit-linear-gradient(top,  rgba(244,116,31,1) 0%,rgba(218,14,6,1) 100%);
    background: linear-gradient(to bottom,  rgba(244,116,31,1) 0%,rgba(218,14,6,1) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4741f', endColorstr='#da0e06',GradientType=0 );
        transform: rotate(40deg);
        opacity: .6;
        right: 100px;
        top: -200px;
        z-index: 10;
    
    }
    .text-block {
        position: relative;
        z-index: 10;
        width: 70%;
        margin: 0 auto;
        padding: 50px;
    }
    .text-block::after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        background: #2b2525;
         z-index: -1;
    }
    h1 {
       position: relative;
        color: #fff;
        z-index: 12;
    }
<div class="wrapper">
        <div class="text-block">
            <h1>Text with the biggest z-index and not covered by red stripe</h1>
        </div>
    </div>

   
css z-index pseudo-element
1个回答
0
投票

我到处都删除了z-index,并像这样将其添加到h1中:

.wrapper {
 position: relative;
  background: #000;
  overflow: hidden;
}

.wrapper::after {
  content: "";
    position: absolute;
    width: 650px;
    height: 1500px;
    background: rgb(244,116,31);
    background: -moz-linear-gradient(top,  rgba(244,116,31,1) 0%, rgba(218,14,6,1) 100%);
    background: -webkit-linear-gradient(top,  rgba(244,116,31,1) 0%,rgba(218,14,6,1) 100%);
    background: linear-gradient(to bottom,  rgba(244,116,31,1) 0%,rgba(218,14,6,1) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4741f', endColorstr='#da0e06',GradientType=0 );
    transform: rotate(40deg);
    opacity: .6;
    right: 100px;
    top: -200px;

}

.text-block {
    position: relative;
    width: 70%;
    margin: 0 auto;
    padding: 50px;
}

.text-block::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background: #2b2525;
}

h1 {
   position: relative;
    color: #fff;
    z-index: 1;
}
© www.soinside.com 2019 - 2024. All rights reserved.