html - 如何对背景图像的特定区域施加模糊效果?

标签 html css

我有一个带有背景图片的 div。在 div 内部,有一个带有文本的居中 div。为了使文本阅读起来更舒适,我想模糊该特定区域中父 div 的背景图像

我想在 text div 上使用 backdrop-filter: blur,但发现 firefox 还不支持它

.parent {
  background: url(...);
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.child {
  width: 300px;
  height: 300px;
  backdrop-filter: blur(10px) ---unfortunately not supported in firefox
}
<div class="parent">
  <div class="child">
    Lorem ipsum
  </div>
</div>

还有其他方法可以模糊背面区域吗?

最佳答案

backdrop-filter 几乎不被支持,只有 Webkit Nightlies但过滤:模糊(10px);得到更多支持。

您可以尝试使用过滤器的替代方法并使用背景附件创建 2 个彼此重叠的部分,较小的部分模糊。

例子:

body {
  background: url(https://placeimg.com/640/480/tech);
  background-attachment: fixed;
  /* prepare for the blurry piece to add */
  background-size: 100vw auto;
  margin: 0;
  min-height: 100vh;
  display: flex;
}

p:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  z-index: -1;
  filter: blur(10px);
  background: url(https://placeimg.com/640/480/tech);
  background-attachment: fixed;
  background-size: 100vw auto;
}

p {
  margin: auto;
  padding: 20vh 10vh;
  /*background:white; if needed */
  position: relative;
  z-index: 1;
  font-size: calc(10px + 2vw);
  border:solid 1px;
  border-radius:1em;
  overflow:hidden;
  box-shadow:2px 2px 2px
}
<p> is this backdrop alternative do the job ? </p>

关于html - 如何对背景图像的特定区域施加模糊效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57785895/

相关文章:

javascript - h1 标签不随 bootstrap 改变颜色

css - 有人可以解释一下这个复杂的 css 的作用吗

javascript - 我的元素甚至在用户点击它触发功能之前就不断显示(点击功能)

Javascript UWP - 我如何为不在主 html 页面中的按钮插入处理程序?

html - 我的移动网站文本已被扭曲

html - asp :TextBox change placeholder via . NET代码隐藏

jquery - 提交 jquery/ajax 表单后更改列表中的图像

javascript - 是否可以从附加的 HTML 中将某些内容返回给函数?

css - 如何设置 Xul 窗口背景图像?或者,如何在图像上添加标题?

jquery - 用 css 或 jquery 重写 !important