CSS3 图片滤镜效果
图片滤镜效果主要是用 filter
属性,它定义了元素的可视效果 blur 给图像设置高斯模糊。
图片滤镜
CSS filter
属性把视觉效果(如模糊和饱和度)添加到元素。
注意:Internet Explorer 或 Edge 12 不支持 filter 属性。
把所有图片的颜色更改为黑白(100% 灰色):
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 33%;
height: auto;
float: left;
max-width: 235px;
}
.blur {filter: blur(4px);}
.brightness {filter: brightness(250%);}
.contrast {filter: contrast(180%);}
.grayscale {filter: grayscale(100%);}
.huerotate {filter: hue-rotate(180deg);}
.invert {filter: invert(100%);}
.opacity {filter: opacity(50%);}
.saturate {filter: saturate(7);}
.sepia {filter: sepia(100%);}
.shadow {filter: drop-shadow(8px 8px 10px green);}
</style>
</head>
<body>
<p><strong>注意:</strong> Internet Explorer 或 Edge 12 不支持 filter 属性。</p>
<img src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="blur" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="brightness" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="contrast" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="grayscale" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="huerotate" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="invert" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="opacity" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="saturate" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="sepia" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
<img class="shadow" src="/images/pineapple.jpg" alt="Pineapple" width="300" height="300">
</body>
</html>
提示:请访问本站的 CSS 滤镜参考手册,了解有关 CSS 滤镜的更多信息。