css Backdrop Filters实现模糊、亮度、 对比度、 灰度、色相、饱和度、反转效果代码
代码语言:html
所属分类:布局界面
代码描述:css Backdrop Filters实现模糊、亮度、 对比度、 灰度、色相、饱和度、反转效果代码,Backdrop Filters 是 CSS3 中的一种新特性,它可以在元素的背景区域添加一层半透明的滤镜效果,使得元素的背景更加模糊或者变暗,从而提高页面的视觉效果。Backdrop Filters 可以应用于所有元素,包括图片、文字、边框等。 要使用 Backdrop Filters,你可以在 CSS 样式中为元素添加 backdrop-filter 属性,然后指定一个滤镜效果,例如模糊或者灰度。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> /* --------------------- */ /* Filters ✨✨✨ */ /* --------------------- */ :root { --filter-blur: 10px; --filter-brightness: 60%; --filter-contrast: 60%; --filter-grayscale: 30%; --filter-hue-rotate: 30%; --filter-saturate: 30%; --filter-invert: 100%; } .Filter[data-filter-name="blur"] .Filter-lens { backdrop-filter: blur(var(--filter-blur)); } .Filter[data-filter-name="brightness"] .Filter-lens { backdrop-filter: brightness(var(--filter-brightness)); } .Filter[data-filter-name="contrast"] .Filter-lens { backdrop-filter: contrast(var(--filter-contrast)); } .Filter[data-filter-name="grayscale"] .Filter-lens { backdrop-filter: grayscale(var(--filter-grayscale)); } .Filter[data-filter-name="hue-rotate"] .Filter-lens { backdrop-filter: hue-rotate(var(--filter-hue-rotate)); } .Filter[data-filter-name="saturate"] .Filter-lens { backdrop-filter: saturate(var(--filter-saturate)); } .Filter[data-filter-name="invert"] .Filter-lens { backdrop-filter: invert(var(--filter-invert)); } /* --------------------- */ /* Global style */ /* --------------------- */ body::before { content: ""; position: fixed; z-index: -1; inset: 0; background-image: url('//repo.bfw.wiki/bfwrepo/image/646f5a527911e.png'); background-size: cover; background-position: center center; } .Header { display: flex; justify-content: space-between; flex-wrap: wrap; padding: 12px 24px; border-bottom: 1px solid #fff; font-weight: 700; color: #fff; backdrop-filter: blur(10px) brightness(60%); } .Container { position: absolute; top: 50%; left: 50%; } .Filter { display: inline-block; position: absolute; top: 0; left: 0; border: 5px solid #fff; border-radius: 3px; box-shadow: 0 0 20px rgba(0, 0, 0, 0.3); transform: translate(-50%, -50%); user-select: none; } .Filter[hidden] { display: none; } .Filter-lens { content: ""; display: block; width: 100%; aspect-ratio: 1/1; cursor: pointer; } .Filter-content { display: flex; align-items: center; justify-content: center; position: relative; width: 300px; height: 70px; padding: 12px 24px; background: #fff; font-size: 1.5rem; text-align: center; } .Filter-name { position: absolute; top: 0; left: 5px; border-radius: 5px; padding: 2px 8px; background: linear-gradient(-25deg, #4affd3, #4a00d3); color: #fff; font-size: 1rem; font-weight: 700; transform: translateY(-50%); } .Filter input { width: 100%; cursor: pointer; } /* --------------------- */ /* Other styles */ /* --------------------- */ * { box-sizing: border-box; } body { margin: 0; font-family: 'Poppins', sans-serif; overflow: hidden; } .Me { position: fixed; z-index: 10; bottom: 20px; left: 50%; color: #000; transform: translateX(-50%); font-weight: 700; opacity: .5; } </style> </head> <body > <header class="Header"> <div> <input id="FilterBlur" name="FilterBlur" type="checkbox" data-filter-name="blur" checked/> <label for="FilterBlur">Blur</label> </div> <div> <input id="FilterBrightness" name="FilterBrightness" type="checkbox" data-filter-name="brightness"/> <label for="FilterBrightness">Brightness</label> </div> <div> <input id="FilterContrast" name="FilterContrast" type="checkbox" data-filter-name="contrast"/> <label for="FilterContrast">Contrast</label> </div> <div> <input id="FilterGrayscale" name="FilterGrayscale" type="checkbox" data-filter-name="grayscale"/> <label for="FilterGrayscale">Grayscale</label> </div> <div> <input id="FilterHueRotate" name="FilterHueRotate" type="checkbox" data-filter-name="hue-rotate"/> <label for="FilterHueRotate">Hue-rotate</label> </div> <div> <input id="FilterSaturate" name="FilterSaturate" type="checkbox" data-filter-name="saturate"/> <label for="FilterSaturate">Saturate</label> </div> <div> <input id="FilterInvert" name="FilterInvert" type="checkbox" data-filter-name="invert"/> <label for="FilterInvert">Invert</label> </div> </header> <main> <div class="Container"> <div class="Filter" data-filter-name="blur"> <div class="Filter-lens"></div> <div class="Filter-content"> <label class="Filter-name" for="blur">Blur</label> <input type="range" id="blur" name="blur" value="10" min="0" max="100" /> </div> </div> <div class="Filter" data-filter-name="brightness" hidden> <div class="Filter-lens"></div> <div class="Filter-content"> <label class="Filter-name" for="brightness">Brightness</label> <input type="range" id="brightness" name.........完整代码请登录后点击上方下载按钮下载查看
网友评论0