HTML/Html-Css/22-定位层级.html
2023-05-01 19:37:40 +08:00

67 lines
1.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width-device-width,initial-scale=1.0">
<title>定位层级</title>
<style>
#app,#app2 {
background-color: salmon;
width: 400px;
height: 400px;
position: relative;
z-index: 0;
}
#app {
z-index: 99;
}
.box {
width: 100px;
height: 100px;
}
.box1 {
height: 150px;
background-color: rgb(255, 0, 0);
position: absolute;
z-index: 1;
}
.box2 {
width: 150px;
background-color: antiquewhite;
position: absolute;
z-index: 0;
}
#app2 .box1 {
top: -249px;
}
#app .box2 {
top: 100px;
}
</style>
</head>
<body>
<div id="app">
<div class="box box1">box1</div>
<div class="box box2">box2</div>
</div>
<div id="app2">
<div class="box box1">box1</div>
<div class="box box2">box2</div>
</div>
<!-- 子绝父相 -->
</body>
</html>