<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>子绝父相定位盒子居中</title>
<style>
.box{
width: 900px;
height: 900px;
background-color: skyblue;
margin: 0 auto;
position: relative;
}
.center1{
width: 300px;
height: 300px;
background-color: pink;
left: 50%;
margin-left: -150px;
position: absolute;
}
.center4{
width: 300px;
height: 300px;
background-color: pink;
top: 50%;
margin-top: -150px;
position: absolute;
}
.center3{
width: 300px;
height: 300px;
background-color: pink;
top: 50%;
margin:-150px 600px;
position: absolute;
}
.center2{
width: 300px;
height: 300px;
background-color: pink;
left: 50%;
margin:600px -150px;
position: absolute;
}
</style>
</head>
<body>
<div class="box">
<div class="center1"></div>
<div class="center2"></div>
<div class="center3"></div>
<div class="center4"></div>
</div>
</body>
</html>
子绝父相定位居中
最新推荐文章于 2023-06-23 18:41:21 发布