html - 叠加层下的文本不显示

标签 html css

<分区>

我制作了一个非常基本的英雄部分,带有背景和叠加层。

.hero
    width: 100%
    height: 100vh
    position: relative
    background-image: url('../assets/hero.png')
    background-position: center
    background-repeat: no-repeat
    background-size: cover

    &:before 
        content: ''
        position: absolute
        top: 0
        right: 0
        bottom: 0
        left: 0
        background: $secondary-blue
        opacity: .5
        overflow: hidden
        z-index: 1

.hero--welcome
    display: flex
    align-items: center
    justify-content: center
    flex-direction: column
    align-items: left
    width: 100%
    height: 100%
    z-index: 2
<div className="hero">
  <div className="hero--welcome">
    <h6>Welcome to</h6>
    <h1>Alhandsya</h1>
  </div>
</div>

但是 hero--welcome 处的文本在叠加层下以非常暗的方式显示,我希望它覆盖它,我该怎么做?我尝试了 z-index 但没有成功。

结果(截图)

Screenshot

最佳答案

您只是将 z-index 添加到 &:before 中,并没有将 z-index 添加到实际的父 div 标签。

此解决方案将起作用:

.hero
    width: 100%
    height: 100vh
    position: relative
    background-image: url('../assets/hero.png')
    background-position: center
    background-repeat: no-repeat
    background-size: cover
    z-index: 1

    &:before 
        content: ''
        position: absolute
        top: 0
        right: 0
        bottom: 0
        left: 0
        background: $secondary-blue
        opacity: .5
        overflow: hidden
        z-index: -1

.hero--welcome
    display: flex
    align-items: center
    justify-content: center
    flex-direction: column
    align-items: left
    width: 100%
    height: 100%
    z-index: 3
<div className="hero">
  <div className="hero--welcome">
    <h6>Welcome to</h6>
    <h1>Alhandsya</h1>
  </div>
</div>

关于html - 叠加层下的文本不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52449429/

相关文章:

javascript - 对象 [] 表示法

html - Div 显示为表格 inside div 显示为表格

html - CSS 未知边距/填充

css - 在 Chrome 中打开 Sans 字母间距

CSS - 在移动到下一列之前,如何设置 UL 列表中 LI 的数量限制

html - 跨浏览器(chrome/firefox)试图获得以像素百分比定义的顶级位置

html - 我如何使这些 <a> 适用于 Firefox 而不仅仅是 Internet Explorer 6

html - 需要从mvc渲染html,只显示html标签而不显示文本

jQuery 如何选择子一级 div

html - 在 CSS/SVG 中是否有一种普遍支持的方法来制作倾斜的 "frosted glass"效果?