通过 css 模糊没有背景图像的元素
To blur an element with no background image by css
在 body
标签上使用 background-image
和
里面有两个 div
。
我需要为每个人都有模糊的背景
div
.
我现在能做的就是设置 background-image
on
每个 div
并使用 filter: blur
属性 来模糊它们。
但是因为我想要整个页面的背景相同(不是每个 div
分开),
我想要的方式是设置 background-image
在 body
标签上,然后模糊 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>
在 body
标签上使用 background-image
和
里面有两个 div
。
我需要为每个人都有模糊的背景
div
.
我现在能做的就是设置 background-image
on
每个 div
并使用 filter: blur
属性 来模糊它们。
但是因为我想要整个页面的背景相同(不是每个 div
分开),
我想要的方式是设置 background-image
在 body
标签上,然后模糊 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>