2017-04-22 28 views
0

这里是我的代码的codepen,因为堆栈溢出还不允许SCSS:https://codepen.io/thedonquixotic/pen/dWXOby英雄Z指数问题?也许溢出相关?

我想做一个部分,其中包含英雄形象和h1。

包含部分有背景渐变。它的z-index设置为1.

包含部分包含一个img和一个h1。 img z-index被设置为-1,并且在渐变背景后面已经正确渲染。

h1的z-index为2,并且应该在图像和渐变之上呈现。

我有这个工作,但后来我添加了一个JS视差脚本。我得到了它的工作。 h1等仍然可见,但行为有点怪异,所以我评论了JS导入,重点是确保我的flex box的东西设置正确。但现在它根本不工作!

body div section.hero { 
 
    display: flex !important; 
 
    width: 100vw; 
 
    height: 81vh; 
 
    background-repeat: no-repeat; 
 
    background-position: center; 
 
    background: linear-gradient(to left, rgba(255, 195, 113, 0.5), rgba(255, 95, 109, 0.5)); 
 
    position: relative; 
 
    z-index: 1; 
 
} 
 
body div section.hero div img { 
 
    display: flex !important; 
 
    width: 100vw; 
 
    height: 81vh; 
 
    z-index: -1 !important; 
 
    flex: 1 1 auto; 
 
} 
 
body div section.hero div.svg-flex { 
 
    position: relative; 
 
    display: flex !important; 
 
    padding: 30px; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
    align-content: center; 
 
    align-items: center; 
 
    z-index: 2; 
 
} 
 
body div section.hero div.svg-flex .hero-text { 
 
    width: 95vw; 
 
    top: 30vh; 
 
    stroke-miterlimit: 10; 
 
    display: flex; 
 
    position: relative; 
 
    overflow: hidden; 
 
    stroke-linejoin: miter; 
 
    font-size: 6rem; 
 
    fill: none; 
 
    stroke: white; 
 
    stroke-width: 2.2px; 
 
} 
 
body div section.hero div.svg-flex h1 { 
 
    position: relative; 
 
    font-family: 'Aller', Arial; 
 
    color: white; 
 
    text-align: center; 
 
    font-size: 3rem; 
 
    line-height: 3rem; 
 
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.35); 
 
    max-width: 70rem; 
 
    margin: 2vh auto 0; 
 
    display: flex !important; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
    align-content: center; 
 
    align-items: center; 
 
    z-index: 2; 
 
}
<section class="hero scene" id="scene" style="display: flex;"> 
 
    <div class="layer" style="display: flex;" data-depth="0.40"><img src="https://s-media-cache-ak0.pinimg.com/originals/32/93/21/329321959fcaf0d24e2349ccf8c9407a.jpg"> 
 
    </div> 
 

 

 

 
<div class="svg-flex layer" data-depth="0.80" style="display: flex;"> 
 
     <h1 class="class-study-title" style="display: flex;"><h1> The Title</h1> 
 
</div> 
 

 
</section>

回答

1

添加这些stlyes到H1

h1 { 
     position: absolute; 
     top: 0px; 
+0

为什么它需要是绝对可以观看这样呢? –

+0

我已经在代码笔中进行了这些更改,但似乎并未解决问题。 –

+0

@ DavidA.French - 我的错误,将样式应用于h1而不是'div.svg-flex'。 –