码迷,mamicode.com
首页 > 其他好文 > 详细

负margin居中

时间:2015-10-15 22:15:55      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:

<!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;
width:200px;
height:200px;
border:1px solid red;
}
</style>
</head>

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

负margin居中

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!