html - 背景过滤器不适用于溢出:隐藏在父级上
问题描述
我试图在 div 上使用背景过滤器(在这种情况下为模糊)只是为了发现溢出:隐藏属性阻止它应用。浏览器是 Chrome 78。
假设我在 div.block 中有一个 div.filter,它是 div.container 中的包装器。
div.container > div.block > div.filter
如果我对 .container 和 .block 应用溢出:隐藏,过滤器的效果会突然消失。此外,.block 的其他属性会阻止应用过滤器。
似乎溢出:隐藏在 .container 上会触发这种不稳定的行为。你们知道这里发生了什么吗?
此处演示:https ://codepen.io/marcel_pi/pen/VwYvmGv
请检查以下代码:
.container{
overflow: hidden; /* delete to resume normal behavior */
border-radius: 20px;
}
.block{
width: 400px;
height: 400px;
border: 4px solid black;
background: linear-gradient(90deg, transparent 50%, rgba(152,47,138,.5) 50%) antiquewhite;
background-size: 30px;
font-weight: bold;
/* the properties below prevent the filter from being applied once the overflow: hidden is applied to .container */
border-radius: 20px; /* delete to resume normal behavior */
overflow: hidden; /* delete to resume normal behavior */
position: relative; /* delete to resume normal behavior */
}
.filter{
position: absolute;
top: 0;
left: 205px;
width: 230px;
height: 230px;
background: #42add77d;
backdrop-filter: blur(6px); /* the blur filter */
border-radius: 20px;
}
<div class="container">
<div class="block">
<div class="filter"></div>
</div>
</div>
解决方案
如果将过滤器 ( 0px
) 应用于应用溢出属性的同一元素,它将起作用。
.container{
overflow: hidden; /* delete to resume normal behavior */
border-radius: 20px;
}
.block{
width: 400px;
height: 400px;
border: 4px solid black;
background: linear-gradient(90deg, transparent 50%, rgba(152,47,138,.5) 50%) antiquewhite;
background-size: 30px;
font-weight: bold;
/* the properties below prevent the filter from being applied once the overflow: hidden is applied to .container */
-webkit-filter: blur(0px);
border-radius: 20px; /* delete to resume normal behavior */
overflow: hidden; /* delete to resume normal behavior */
position: relative; /* delete to resume normal behavior */
}
.filter{
position: absolute;
top: 0px;
left: 205px;
width: 230px;
height: 230px;
background: #42add77d;
backdrop-filter: blur(4px);
border-radius: 20px;
}
<div class="container">
<div class="block">
<div class="filter"></div>
</div>
</div>
你也可以在这里测试它..
推荐阅读
- lightroom - 如何将一堆图片移动到 Lightroom Classic 中的新根文件夹?
- image - 如何通过检查网站元素来断定网站不接受上传?
- azure-blob-storage - 忽略来自天蓝色核心的杰克逊 XmlMapper
- r - 使用具有位置 jitterdodge 的第三个值时数据点未对齐
- c# - 将浮点变量设置为数组值
- vba - 尝试打开 ppt 文件时出错 & 其他几个疑问 (powerpoint)
- powershell - psql:使用 powershell 变量查询失败
- selenium - 如何找到一个复选框并知道它在表格单元格中的选中状态
- python - 无法使用 Python 读取 .cdb 文件
- azure - 微软博览会 OAuth 登录