Home > Web Front-end > CSS Tutorial > How to set the background image to be transparent in css

How to set the background image to be transparent in css

青灯夜游
Release: 2021-10-12 18:23:59
Original
34264 people have browsed it

In CSS, you can use the opacity attribute to set the background image to be transparent. The function of this attribute is to set the transparency of the element. You only need to add the "opacity: transparency value;" style to the element with the background image set. .

How to set the background image to be transparent in css

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

In CSS, you can use the opacity attribute to set the background image to be transparent.

The Opacity attribute sets the transparency level of an element. The transparency level (property value) ranges from 0.0 (fully transparent) to 1.0 (fully opaque).

Code example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<style>
			div{
				width: 400px;
				height: 230px;
				background:url(img/3.jpg) no-repeat;
				background-size: 400px 226px;
			}
			.box{
				opacity: 0.5;
			}
		</style>
	</head>

	<body>	
		<div></div> 
        <div class="box"></div> 
	</body>

</html>
Copy after login

Effect picture:

How to set the background image to be transparent in css

(Learning video sharing: css video Tutorial)

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