Home  >  Article  >  Web Front-end  >  How to set transparency to background image in html

How to set transparency to background image in html

青灯夜游
青灯夜游Original
2022-01-21 12:00:1757486browse

htmlHow to set the transparency of the background image: 1. Use the opacity attribute to add the "opacity: transparency value;" style to the element that sets the background image; 2. Use the filter attribute to set the background image. Just add the "filter: opacity (transparency value);" style to the element.

How to set transparency to background image in html

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

htmlSet the transparency of the background image

1. Use the opacity attribute

<!DOCTYPE html>
<html>
	<head>
		<style type="text/css">
			div {
				width: 300px;
				height: 300px;
				background-image: url(img/3.jpg);
			}
			.box{
				opacity: 0.5;
			}
		</style>
	</head>

	<body>
		<div>背景图片</div>
		<div class="box">背景图片</div>
	</body>

</html>

How to set transparency to background image in html

2. Use the filter attribute

<!DOCTYPE html>
<html>
	<head>
		<style type="text/css">
			div {
				width: 300px;
				height: 300px;
				background-image: url(img/3.jpg);
			}
			.box{
				filter: opacity(0.6);
			}
		</style>
	</head>

	<body>
		<div>背景图片</div>
		<div class="box">背景图片</div>
	</body>

</html>

How to set transparency to background image in html

##Related recommendations: "

html video tutorial

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