html - 通过 css 模糊没有背景图像的元素

标签 html css blur

使用 background-imagebody标记和
两个div在里面。
我需要为每个人设置模糊的背景div .
我现在能做的就是设置 background-image
每个div并使用 filter: blur属性来模糊它们。

但因为我想要整个页面的背景相同(每个 div 不分开),
我想要的方式是设置 background-imagebody标记然后模糊 div元素。

这就是我尝试过的:

body {
    background-image: url(public/images/billy-huynh-W8KTS-mhFUE-unsplash\ \(1\).jpg);
    background-attachment: fixed;
    background-size: cover;
    display: grid;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    position: relative;
}

.parent-div::before {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    filter: blur(5px);

}

.parent-div {
    position: relative;
}

HTML代码:
<body>
<div class=" parent-div">
    <div class=" child-div">
        <h4 class=" text-light">Hello world!!</h4>
    </div>
</div>
<div class=" parent-div">
    <div class=" child-div">
        <h4 class=" text-light">Hello world!!</h4>
    </div>
</div>

其实我想模糊div没有背景图像的元素。
有没有办法这样做?
谢谢

最佳答案

您要找的是 backdrop-filter

body {
  background-image: url(https://i.picsum.photos/id/174/800/800.jpg);
  background-attachment: fixed;
  background-size: cover;
  height: 100vh;
  margin:0;
  position: relative;
}


.parent-div {
  position: relative;
  height:50vh;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
<div class=" parent-div">
  <div class=" child-div">
    <h4 class=" text-light">Hello world!!</h4>
  </div>
</div>
<div class=" parent-div">
  <div class=" child-div">
    <h4 class=" text-light">Hello world!!</h4>
  </div>
</div>

关于html - 通过 css 模糊没有背景图像的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60921473/

相关文章:

javascript - JQuery Mobile 与 Knockout 结合使用

javascript - 当覆盖菜单打开时隐藏主滚动条

javascript - onClick 按钮最大字符长度

具有透明度的 CSS 模糊背景(就像在 iOS7 中一样)

html - 在 cinder 应用程序中渲染 html

html - 如何使响应速度达到 2/3 行

html - 使用 float 时保持底部边距

javascript - jQuery Blur() ....它到底是如何工作的?

javascript - 替换后字符提交错误

html - CSS 中的多列布局首先填充第一列并正确打印到多个页面