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

How to set the transparency of the background image in css

王林
王林Original
2020-11-13 11:59:1526739browse

How to set the transparency of the background image in css: You can use the opacity attribute to set it, such as [opacity: value|inherit;]. value specifies the opacity, and inherit specifies the value of the opacity attribute inherited from the parent element.

How to set the transparency of the background image in css

Attribute introduction:

The opacity attribute sets the opacity level of the element.

(Learning video sharing: css video tutorial)

Grammar:

opacity: value|inherit;

Attribute value:

value Regulations Opacity. From 0.0 (fully transparent) to 1.0 (fully opaque).

inherit The value of the opacity attribute should be inherited from the parent element.

Example:

Tip: The opacity attribute cannot be directly added to the background image in CSS. You can use the following method to bypass this restriction.

div {
  width: 200px;
  height: 200px;
  display: block;
  position: relative;
}

div::after {
  content: "";
  background: url(image.jpg);
  opacity: 0.5;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  z-index: -1;   
}

Related recommendations: CSS tutorial

The above is the detailed content of How to set the transparency of the background image 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