html - 如何模糊div的背景图像,而不模糊其余站点或div的内容

标签 html css background-image blur

我正在尝试弄清楚如何模糊 div 的背景图像。目标是仅模糊 div 的背景图像,而不模糊页面本身的背景或 div 内容。

这是一个 div 示例:

<header class="intro">
  <div class="background-image"></div>
  <div class="intro-body">
    <div class="container">
      <div class="row">
        <div class="col-md-8 col-md-offset-2">
          <h1 class="brand-heading">Grayscale</h1>
          <p class="intro-text">A free, responsive, one page Bootstrap theme.
            <br>Created by Start Bootstrap.</p>
          <a href="#about" class="btn btn-circle page-scroll">
            <i class="fa fa-angle-double-down animated"></i>
          </a>
        </div>
      </div>
    </div>
  </div>
</header>

CSS:

body {
  width: 100%;
  height: 100%;
  font-family: "Lora", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: white;
  background-color: black;
}

.intro {
  display: table;
  width: 100%;
  height: auto;
  padding: 100px 0;
  text-align: center;
  color: white;
}

.intro .background-image {
  z-index: 1;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: auto;
  background-image: url(https://previews.123rf.com/images/denisovd/denisovd1203/denisovd120301652/12705959-wall-of-wooden-barrels-Stock-Photo-barrels-whiskey-cellar.jpg) no-repeat bottom center scroll;
  background-color: black;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  -o-background-size: cover;
  -webkit-filter: blur(5px);
  -moz-filter: blur(5px);
  -o-filter: blur(5px);
  -ms-filter: blur(5px);
  filter: blur(5px);
}

.intro .intro-body {
  z-index: 9999;
  display: table-cell;
  vertical-align: middle;
}

这是包含我尝试过的 CSS 的 JS fiddle : http://jsfiddle.net/80jzdvqp/

我非常感谢一些帮助!

最佳答案

解决办法在这里

<body><header class="intro">
  <div class="background-image"></div>
  <div class="intro-body">
    <div class="container">
      <div class="row">
        <div class="col-md-8 col-md-offset-2">
          <h1 class="brand-heading">Grayscale</h1>
          <p class="intro-text">A free, responsive, one page Bootstrap theme.
            <br>Created by Start Bootstrap.</p>
          <a href="#about" class="btn btn-circle page-scroll">
            <i class="fa fa-angle-double-down animated"></i>
          </a>
        </div>
      </div>
    </div>
  </div>
</header>
</body>

CSS:

body {
    width: 100%;
    height: 100%;
    font-family: "Lora", "Helvetica Neue", Helvetica, Arial, sans-serif;
    color: white;
    background-color: black;
    margin: 0;
    padding: 0;
}

.intro {
    display: table;
    width: 100%;
    height: auto;
    padding: 100px 0;
    text-align: center;
    color: white;
}

.intro .background-image {
    z-index: -1;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: url(https://wallpaperbrowse.com/media/images/html-color-codes-color-tutorials-hero-00e10b1f.jpg);
    -webkit-filter: blur(10px);
    filter: blur(10px);
}

.intro .intro-body {
  z-index: 9999;
  display: table-cell;
  vertical-align: middle;
}

关于html - 如何模糊div的背景图像,而不模糊其余站点或div的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42979398/

相关文章:

html - 将 <br> 替换为使其宽度适应容器 : possible? 的水平线

css - 在 Rails/bootstrap 中,为什么背景图像不能正确拉伸(stretch)?

php - 将背景图像添加到整个屏幕,跨所有 div

html - 搜索引擎如何解释<del>标签?

javascript - 选择选项排序最后一个选项成为第一个

html - 在背景图像之前/之后使用 css 中的数据属性

html - 如何保留空格但忽略 CSS 中的换行符?

javascript - ReactJs——在 li 元素的点击事件上,类不会立即添加

html - Css,在中心div的两侧包装两个div

css - 使用 CSS 属性从 Sprite 裁剪 Logo