Home>Article>Web Front-end> How to set the transparency of images in css

How to set the transparency of images in css

青灯夜游
青灯夜游 Original
2021-04-21 15:51:39 20782browse

How to set image transparency in css: 1. Use the filter attribute to add the "filter:opacity(value%)" style to the image element; the value is between 0 and 100, and "0%" is completely transparent. , "100%" means there is no change in the image. 2. Use the opacity attribute, the syntax "opacity: value".

How to set the transparency of images in css

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

Method 1: Use the filter attribute--filter:opacity(%)

The filter attribute defines the visibility of the element (usually) Effects (e.g. blur and saturation).

opacity(%): used to convert the transparency of the image. The value defines the scale of the conversion. A value of 0% means complete transparency, a value of 100% means no change to the image. Values between 0% and 100% are linear multipliers of the effect, equivalent to multiplying the number of image samples. If the value is not set, the value defaults to 1. This function is very similar to the existing opacity attribute, except that through filter, some browsers provide hardware acceleration to improve performance.

Example:

     

原图:

  How to set the transparency of images in css

透明度为50%:

  How to set the transparency of images in css

透明度为20%:

  How to set the transparency of images in css

Rendering:

How to set the transparency of images in css

##Method 2: Use the opacity attribute

The Opacity attribute sets the transparency level of an element. Range of values: from 0.0 (fully transparent) to 1.0 (fully opaque).

Example:

     

原图:

  How to set the transparency of images in css

透明度为0.5:

  How to set the transparency of images in css

透明度为0.2:

  How to set the transparency of images in css

Rendering:


How to set the transparency of images in css

(Learning video sharing:

css video tutorial)

The above is the detailed content of How to set the transparency of images in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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