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

div居中的三种方法

时间:2014-10-20 23:17:59      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   sp   div   on   ef   bs   tt   

方法1:

#div1{

    width:200px;

    height:200px;

    background:green;

    position:absolute;

    left:0;

    top:0;

    right:0;

    bottom:0;

    margin:auto;

}
方法2:

#div1{

    width:400px;

    height:400px;

    background:green;

    position:absolute;

    left:50%;

    top:50%;

    margin:-200px 0 0 -200px;

}
方法3:

#div1{

    display:table-cell;

    text-align:center;

    vertical-align:middle;

}//图片的居中方法

div居中的三种方法

标签:io   os   ar   sp   div   on   ef   bs   tt   

原文地址:http://www.cnblogs.com/cdwp8/p/4039046.html

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