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

让一个div 上下左右居中

时间:2017-07-30 17:13:21      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:idt   osi   order   top   round   居中   ott   sla   form   


方法1:
.div1{
         width:400px;
         height:400px;
         border:#CCC 1px solid;
         background:#99f;
         position:absolute;
         left:50%;
         top:50%;
         transform: translate(-50%,-50%);
}                        
<div class="div1"></div>
方法2:
.div2{
    width:400px;
    height:400px;
    border:#CCC 1px solid;
    background:#99f;
    position: absolute;
    left:0;
    top: 0;
    bottom: 0;
    right: 0;
    margin: auto;
}
<div class="div2"></div>
方法3:
.div3{
    width:400px;
    height:400px;
    border:#CCC 1px solid;
    background:#9f9;
    position: absolute;
    left: 50%;
    top:50%;
    margin-left:-200px;
    margin-top: -200px;        
}
<div class="div3"></div>

让一个div 上下左右居中

标签:idt   osi   order   top   round   居中   ott   sla   form   

原文地址:http://www.cnblogs.com/oldZhangFeng/p/7259328.html

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