How to set the transparency of div in html

青灯夜游
Release: 2021-12-13 15:28:59
Original
18753 people have browsed it

htmlHow to set the transparency of div: 1. Using the opacity attribute, you only need to add the "opacity: transparency value;" style to the div element; 2. Using the filter attribute, you only need to add "filter" to the div element. :opacity (transparency value);" style.

How to set the transparency of div in html

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

htmlSet the transparency of div

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			.box1{
				width: 300px;
				height: 200px;
				background-color: yellow;
			}
			.box2{
				width: 100px;
				height: 100px;
				background-color: green;
			}
		</style>
	</head>
	<body>
		<div class="box1">
			<div class="box2"></div>
		</div>
	</body>
</html>
Copy after login

How to set the transparency of div in html

1. Use the opacity attribute to set the transparency The smaller the value, the more transparent it is.

.box2{
	width: 100px;
	height: 100px;
	background-color: green;
	opacity: 0.8;
}
Copy after login

How to set the transparency of div in html

.box2{
	width: 100px;
	height: 100px;
	background-color: green;
	opacity: 0.5;
}
Copy after login

How to set the transparency of div in html

.box2{
	width: 100px;
	height: 100px;
	background-color: green;
	opacity: 0.2;
}
Copy after login

How to set the transparency of div in html

2. Use filter: opacity (transparency value);, the smaller the transparency value, the more transparent it is.

.box2{
	width: 100px;
	height: 100px;
	background-color: green;
	filter:opacity(0.5);
}
Copy after login

How to set the transparency of div in html

.box2{
	width: 100px;
	height: 100px;
	background-color: green;
	filter:opacity(0.1);
}
Copy after login

How to set the transparency of div in html

Recommended tutorial: "html video tutorial"

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

Related labels:
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