html - 我如何模糊文本后面的背景

标签 html css background blur

谁能帮我找出这里做错了什么?我试图将文本置于背景之上,但如果我使用 z-index: -1; 它将消失或只是转到后面并且将无法看到它。并且也不会介意说是否有更好的方法来改革所有这些代码。

html, body {margin:0;padding:0}

.page-title {
  position: absolute;
  max-width: 38%;
  top: 50px;
  left: 0;
}

.hero-title {
  background: rgba(0,0,0,.4);
  padding: 15px 15px 15px 40px;
}

.hero-title::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  z-index: 1;
  background: rgba(0, 0, 0, 0.5);
  width: 100%;
  height: 100%;
  -webkit-filter: blur(5px);
  -moz-filter: blur(5px);
  -o-filter: blur(5px);
  -ms-filter: blur(5px);
  filter: blur(5px);
}

.text-wraper {
  z-index: 700;
  color: #fff;
  width: 100%;
}

.main-title {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -1pt;
  line-height: 1em;
  text-transform: uppercase;
}

.sub-title {
  font-size: 24px;
  font-weight: 300;
  line-height: 1em;
  text-transform: uppercase;
}
<div class="hero-image">
  <span class="deskTop1280">
    <img src="http://via.placeholder.com/1280x500/246D5F" width="100%" alt="">
  </span>
</div>
<div class="page-title">
  <div class="hero-title">
    <div class="text-wraper">
      <div class="main-title">Main title goes here</div>
      <div class="sub-title">sub title goes here</div>
    </div>
  </div>
</div>

最佳答案

为了使z-index生效,它需要伴随这样的位置规则:

.text-wraper {
  z-index: 700;
  position: relative;
  color: #FFFFFF;
  width: 100%;
}

您实际上不需要 .text-wraper 上的 z-index。我在以下位置整理了一个示例:https://codepen.io/anon/pen/JMLveE?editors=1100 .

关于html - 我如何模糊文本后面的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48195719/

相关文章:

javascript - 后退按钮不适用于 JQuery 更改功能

html - Bootstrap 表单组对齐

php - 使用 jquery 传递的 GET 变量

php - 由于某种原因,我的链接栏上的背景图片没有显示

android - 应用程序启动期间的白色背景

html - 当用户使用 django 2.2 登录时将登录页面重定向到主页

javascript - 将 HTML 代码放在 JointJS 链接上

java - 如何阻止 JButton 背景仅显示为边框

html - 将 <p> 与左浮动 div 一起使用会导致第二个 div 低于第一个 div

javascript - 使用 jQuery 创建动态 div