效果图
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>透明度</title>
<style>
div {
position: relative;
width: 200px;
height: 200px;
}
.box1 {
background-color: pink;
}
.box2 {
position: absolute;
top: 100px;
left: 100px;
background-color: skyblue;
opacity: 0.5;
/* opacity 的取值范围是 0 到 1 ,其中 0 表示完全透明,1 表示完全不透明 */
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>