css 代码:
filter: grayscale(1)
为了更好兼容,可以加-webkit-
filter:grayscale(1); -webkit-filter:grayscale(1)
原理:使用了css特性filter(滤镜)配合grayscale(将图像转换为灰度图像0%到100%)
filter样式加到哪里
添加到body
如果网页有绝对和固定定位元素,一定要加到html上
引用:
A value other than none for the filter property results in the creation of a containing block for absolute and fixed positioned descendants unless the element it applies to is a document root element in the current browsing context. The list of functions are applied in the order provided.
翻译:
对于filter属性,除none之外的值会导致为绝对和固定位置的后代创建containing block,除非它所应用的元素是当前浏览上下文中的文档根元素。函数列表按提供的顺序应用。