css3的filter(滤镜)属性

filter属性定义了元素(通常是<img>)的可视效果,例如:模糊与饱和度。

none 默认值,没有效果
blur(px)

给图像设置高斯模糊,值越大越模糊。默认值为0

brightness(%) 给图片应用一种线性乘法,使其看起来更亮或更暗。0%:全黑。100%:图像无变化。>100%:图像比原来更亮。默认为1
contrast(%) 调整图像的对比度。0%:全黑。100%:图像不变。>100%:运用更低的对比,默认为1
drop-shadow(h-shadow v-shadow blur spread color) 给图像设置阴影效果。
grayscale(%) 将图像转换为灰度图像。100%:全灰度。0%:图像无变化。
hue-rotate(deg) 给图像应用色相旋转。0deg:无变化。默认为0deg
invert(%) 反转输入图像。100%:完全反转。0%:图像无变化。
opacity(%) 转化图片的透明度。0%:完全透明。100%:图像无变化。
saturate(%) 转换图像饱和度。0%:完全不饱和。100%:图像无变化。默认值1
sepia(%) 将图像转换为深褐色。100%:深褐色。0%:图像无变化。默认值0
url() url函数接受一个xml文件,该文件设置了一个svg滤镜,且可以包含一个锚点来指定一个具体的滤镜元素。

效果图:

代码实现:

<!DOCTYPE html>
<html>
  <head>
  <style>
    body {
      width: 800px;
      margin: 0 auto;
    }
    img {
      width: 200px;
      height: auto;
      float: left;
      margin: 10px;
    }
    .blur {
      -webkit-filter: blur(4px);
      filter: blur(4px);
    }
    .brightness {
      -webkit-filter: brightness(0.30);
      filter: brightness(0.30);
    }
    .contrast {
      -webkit-filter: contrast(180%);
      filter: contrast(180%);
    }
    .grayscale {
      -webkit-filter: grayscale(100%);
      filter: grayscale(100%);
    }
    .huerotate {
      -webkit-filter: hue-rotate(180deg);
      filter: hue-rotate(180deg);
    }
    .invert {
      -webkit-filter: invert(100%);
      filter: invert(100%);
    }
    .opacity {
      -webkit-filter: opacity(50%);
      filter: opacity(50%);
    }
    .saturate {
      -webkit-filter: saturate(7);
      filter: saturate(7);
    }
    .sepia {
      -webkit-filter: sepia(100%);
      filter: sepia(100%);
    }
    .shadow {
      -webkit-filter: drop-shadow(8px 8px 10px orange);
      filter: drop-shadow(8px 8px 10px orange);
    }
  </style>
  </head>
  <body>
    <img
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="blur"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="brightness"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="contrast"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="grayscale"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="huerotate"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="invert"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="opacity"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="saturate"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="sepia"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
    <img
      class="shadow"
      src="https://qnimage.bamaying.com/1536337766741690f982202308e13fbb1fab4b1ea55be34069a4aa5b887a4450c17c1ebec7550.jpg?imageView2/2/w/400/h/400/interlace/1/q/75"
      alt="图片"
      width="300"
      height="300">
  </body>
</html>

猜你喜欢

转载自blog.csdn.net/liya_nan/article/details/82752981