Home > Web Front-end > CSS Tutorial > How to write css code to remove color from images

How to write css code to remove color from images

WBOY
Release: 2021-11-30 18:30:22
Original
3697 people have browsed it

The writing method of picture decolorization code in css is: "picture element {filter:grayscale(100%);}"; the filter attribute is used to set the visual effect of the picture, and can be adjusted when used with the grayscale() function The grayscale of the image. When the grayscale value is set to "100%", the image decolorization effect can be achieved.

How to write css code to remove color from images

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

How to write css code to remove color from images

We can use the filter attribute To write an image decolorization, the filter attribute defines the visual effect (for example: blur and saturation) of the element (usually How to write css code to remove color from images).

When the attribute value is grayscale, convert the image to grayscale. The value defines the scale of the conversion. If the value is 100%, the image will be completely converted to grayscale, and if the value is 0%, the image will remain unchanged. Values ​​between 0% and 100% are linear multipliers of the effect. If not set, the value defaults to 0;

Let’s take a look at the example below:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <style>
.img1 {
    filter: grayscale(100%);
}
    </style>
  <img  src="1118.02.png" class="img1" alt="How to write css code to remove color from images" >
  <img  src="1118.02.png" class="img2" alt="How to write css code to remove color from images" >
</body>
</html>
Copy after login

Output result:

How to write css code to remove color from images

(Learning video sharing: css video tutorial)

The above is the detailed content of How to write css code to remove color from images. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template