CSS3将图片元素的颜色为灰色grayscale()方法

Summary

Converts an element’s color to a shade of gray, for use by the filter property. A decimal value between 0 and 1 or percentage up to 100% controls the extent of the gray effect.

This CSS property value is reflected in the following image:

filter: grayscale(1);
filter: grayscale(100%); /* same */

f05-boatonlake.jpg f06-boatonlakegray.jpg

Compatibility

There is no data available for topic “css”, feature “grayscale”. If you think that there should be data available, consider opening an issue.

Examples

View live exampleThe following example shows the difference between two images, where one has a grayscale of 75%.

filter grayscale.png

HTML

<!DOCTYPE html>
<html>
  <head>
    <title>Filter example</title>
    <style>
      .foo {
        float: left;
      }

      .bar { 
        -webkit-filter: grayscale(75%);
      }
    </style>
  </head>
  <body>
    <img src="http://www.webplatform.org/logo/wplogo_transparent_xlg.png&quot; class="foo" />
    <img src="http://www.webplatform.org/logo/wplogo_transparent_xlg.png&quot; class="foo bar" />
  </body>
</html>

You may also like...

发表评论