Home>Article>Web Front-end> Can I change the color of an image using css?
css can change the color of the picture. The method to change the color of the picture: first create an HTML sample file; then change the color of the picture by setting the attribute of the picture to "img {filter: grayscale(10);}" That’s it.
The operating environment of this tutorial: windows7 system, css3 version, thinkpad t480 computer.
Recommended: "css video tutorial"
css can change the color of the picture.
The filter attribute defines the visual effect of the element (usually). This attribute is mainly used for image content.
This attribute is a CSS method that applies filter effects to elements (mainly images) on the web page.
Syntax:
filter: none|blur()|brightness()|contrast()|drop-shadow()|grayscale()|hue-rotate()|invert()|opacity()|saturate()|sepia()|url();
Filter function
Note: Filters usually use percentages (such as: 75%), of course, they can also be expressed in decimals (such as: 0.75).
none: This is the default value and no effects apply.
brightness(): Set the brightness of the element. If the brightness is 0% it is completely black, if the brightness is 100% it is the same as the original brightness. Values greater than 100% result in brighter elements.
grayscale(): Sets the grayscale of the element, which converts the element color to black and white. Grayscale 0% represents the original element, and 100% represents the completely grayscale element.
sepia(): It converts the image to a sepia image, where 0% means the original image and 100% means full sepia.
contrast(): used to adjust the contrast of elements. 0% contrast means complete black elements, 100% contrast means original elements.
saturate(): used to set the saturation of the element. 0% saturation means the element is completely unsaturated, 100% saturation means the original image. Values greater than 100% of the results are supersaturated elements.
blur(): It applies a blur effect to an element. If no fuzzy value is specified, the default value is 0.
opacity(): It sets the opacity effect of the image. 0% opacity means the element is completely transparent, and if the opacity is 100%, it means the original image.
hue-rotate(): It applies hue rotation to the image. This value defines the degree around which the color circle of the image sample will be adjusted. The default value is 0deg, which represents the original image; although this value has no maximum value, a value exceeding 360deg is equivalent to going around again.
invert(): It inverts the elements. The default value is 0%, which represents the original image. 100% makes the image completely inverted.
drop-shadow(): It applies a shadow effect to the element. It accepts h-shadow, v-shadow, blur, spread and color as values.
url(): Accepts an XML file that sets an SVG filter and can contain an anchor to specify a specific filter element.
Description: Multiple filters can be applied to an element by passing multiple filter functions to the filter attribute; the functions are space-separated.
Example 1: Use a grayscale filter to change a color image to a grayscale image
Original image:
Code:
转换为灰度图像
Rendering:
Example 2: This example uses many filters on the image.
将图像转换为不同的颜色