负margin居中

<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta name="author" content="胡超" />
<meta charset="utf-8"/>
<style type="text/css">
div { /*负边距margin使居中,首先定位到50% 然后再通过负边距拉回 元素高的一半 宽的一半*/
position:absolute;
top:50%;
left:50%;
margin:-100px 0 0 -100px;
200px;
height:200px;
border:1px solid red;
}
</style>
</head>

<body>
<div>
</div>
</body>
</html>

原文地址:https://www.cnblogs.com/12606huchao/p/4883542.html