backdrop-filter: blur(12px); 设置模糊
下面记录了两个模糊的方法
.child{
background-color: rgba(0,0,0,0.6);
backdrop-filter: blur(12px);
}
.child-box{
filter:blur(12px)
}
踩坑
出现的原因
当祖籍元素or父级元素 都含有模糊的属性
但是子元素也要设置模糊的情况下 祖籍元素的模糊生效而子元素模糊不会生效
解决方法如下
我们将祖or父元素的模糊改成伪类的形式
那么子元素和父元素(祖籍)将都有模糊的效果
.gfather:hover .gfather::before{
content:'';
height: 100%;
width: 100%;
position: absolute;
z-index: -1;
background-color: rgba(0,0,0,0.6);
backdrop-filter: blur(12px);
}
.father{
position: relative;
}
.child{
width: 500px;
height: 200px;
background-color: rgba(0,0,0,0.6);
backdrop-filter: blur(12px);
}
实际的案例
做一个hover后的蒙层效果
css
.animediv {
width: calc(100% / 9);
margin: 5px 12px;
position: relative;
&:hover .animetext {
display: flex;
cursor: pointer;
align-items: center;
justify-content: center;
}
.animetext {
display: none;
top: 0;
right: 0;
width: 100%;
height: 100%;
position: absolute;
background-color: rgba(0, 0, 0, 0.1);
backdrop-filter: blur(12px);
color: #fff;
text-align: center;
font-weight: 600;
font-size: 18px;
}
img {
margin: auto;
}
}
html
<div className="animebox">
{datajs.map((item) => {
return (
<div key={item.id} className="animediv">
<div className="centerimg">
<img src={item.src} alt="" />
</div>
<div className="animetext">{item.name}</div>
</div>
);
})}
</div>