1. 代码
- 父盒子:宽度400px,高度200px
- 子盒子:宽度200px,高度100px
<!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>Document</title>
<style>
.outer {
width: 400px;
height: 200px;
background-color: pink;
position: relative;
}
.inner {
width: 200px;
height: 100px;
background-color: skyblue;
position: absolute;
margin: 10%;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner"></div>
</div>
</body>
</html>
2. 效果
- F12查看