CSS背景过滤器“backdrop-filter”
阅读次backdrop-filter
CSS属性允许您对元素后面的区域执行"模糊"、"改变颜色"等效果。因为它适用于元素后面的所有内容, 所以要查看效果, 必须使元素或其背景至少部分透明。
/* Keyword value */ backdrop-filter: none; /*不对背景应用任何过滤器*/ /* URL to SVG filter */ backdrop-filter: url(commonfilters.svg#filter); /* Filter functions */ backdrop-filter: blur(2px); /*模糊*/ backdrop-filter: brightness(60%); /*亮度*/ backdrop-filter: contrast(40%); /*对比度*/ backdrop-filter: drop-shadow(4px 4px 10px blue); /*图像后方阴影*/ backdrop-filter: grayscale(30%); /*灰度*/ backdrop-filter: hue-rotate(120deg); /*整体色调调整*/ backdrop-filter: invert(70%); /*反正图像颜色*/ backdrop-filter: opacity(20%); /*透明度*/ backdrop-filter: sepia(90%); /*转为棕褐色*/ backdrop-filter: saturate(80%); /*饱和度*/ /* Multiple filters */ backdrop-filter: url(filters.svg#filter) blur(4px) saturate(150%); /*多重过滤*/ /* Global values */ backdrop-filter: inherit; backdrop-filter: initial; backdrop-filter: unset;
代码示例
CSS
.box { background-color: rgba(255, 255, 255, 0.3); border-radius: 5px; font-family: sans-serif; text-align: center; line-height: 1; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); max-width: 50%; max-height: 50%; padding: 20px 40px;} html,body { height: 100%; width: 100%;} body { background-image: url('http://lorempixel.com/400/200/'); background-position: center center; background-repeat: no-repeat; background-size: cover;} .container { align-items: center; display: flex; justify-content: center; height: 100%; width: 100%;}
HTML
<div class="container"> <div class="box"> <p>backdrop-filter: blur(10px)</p> </div> </div>