Home > Web Front-end > CSS Tutorial > How to set element transparency in css

How to set element transparency in css

青灯夜游
Release: 2023-01-07 11:43:39
Original
7995 people have browsed it

In CSS, you can use the opacity attribute to set the transparency of an element. You only need to add the "opacity:value;" style to the element; the parameter "value" specifies the transparency of the element, and the value range is " 0.0~1.0", "0.0" means completely transparent, "1.0" means completely opaque.

How to set element transparency in css

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

CSS sets the transparency (opacity) of the element

Method: Use CSS3 opacity attribute

Function: Set the element's transparency Transparency

Syntax:

js

object.style.opacity=value
Copy after login

css

opacity: value|inherit;
Copy after login

Parameters:

  • value: Specified transparency; range from 0.0~1.0, 0.0 means completely transparent, 1.0 means completely opaque.

  • inherit: The value of opcity is inherited from the parent element;

Demo:

<!DOCTYPE html>
<html>
<head>
	<style> 
	div {
		background-color:red;
	}
	.demo{
		opacity:0.4;
		filter:Alpha(opacity=40); /* IE8 and earlier */
	}	
	</style>
</head>
<body>
	<div =>此元素不透明</div><br />
	<div class="demo">此元素的透明度为0.4!注意,文本和背景颜色都受不透明度级别的影响!</div>
 
</body>
</html>
Copy after login

Effect Picture:

How to set element transparency in css

(Learning video sharing: css video tutorial)

The above is the detailed content of How to set element transparency in css. 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