定位盒子居中

<html>
	<head>
		<meta charset="utf-8">
		<title></title>
    </head>
    <style>
        #box1{width:300px;height:300px;border: 1px black solid;position: relative;}
        #box2{width:100px;height:100px;background: red;position: absolute;left:50%;top: 50%;margin: -50px 0 0 -50px;  }
    </style>
	<body>
        <div id="box1">
            <div id="box2"></div>
        </div>
	</body>
</html>
posted @ 2020-07-18 16:47  无敌臭弟弟  阅读(144)  评论(3编辑  收藏  举报