绝对定位元素的居中

方法一
.element { width: 600px; height: 400px; position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto; /* 有了这个就自动居中了 */ }

 

方法二
.element{
  width: 100px;
  position: absolute;
  left: 50%;
  margin-left: -50px;
}
2个方法都需要有个宽度

 

posted @ 2015-07-09 21:12  Debugor  阅读(97)  评论(0)    收藏  举报