/*浏览器变大缩小也不会改变盒子的居中位置*/
<!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>
.box{
position: absolute;
/* 1 left 走50% 父容器宽度的一半; */
left: 50%;
margin-left: -100px;
width: 200px;
height: 200px;
background-color: aqua;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
前端 绝对定位盒子的居中算法
猜你喜欢
转载自blog.csdn.net/qq_55061257/article/details/119250963
今日推荐
周排行