首页 > 其他 > 详细

垂直水平居中的几种方法

时间:2017-03-27 18:33:08      阅读:255      评论:0      收藏:0      [点我收藏+]
1,(元素在容器中垂直水平居中)
css: .box{width:800px;height:800px;background:#ccc;display:flex;justify-content:center;align-items:center;}
               .box div{width:300px;height:300px;background:red;}
html:  <div class="box">
               <div></div> 
          </div>
 
 
2,(元素在容器中垂直水平居中)
css: .box{width:800px;height:800px;background:#ccc;display:flex;justify-content:center;}
               .box div{width:300px;height:300px;background:red;align-self:center;}
html:  <div class="box">
                <div></div> 
          </div>
 
 
3,(元素在页面垂直水平居中)
css:   .box{width:800px;height:800px;background:red;position:fixed;left:0;right:0;top:0;bottom:0;margin:auto;}
html:  <div class="box"></div>
 
 
4,(元素在容器中垂直水平居中)
css:    .box{width:800px;height:800px;text-align:center;}
          .box .box2{display:inline-block;vertical-align:middle;}
          .box span{display:inline-block;width:0px;height:100%;vertical-align:middle;}
html:   <div class="box">
                   <a class="box2">垂直水平居中</a><span></span>                    
           </div>
           <!--要在元素后面不换行加空的span-->

垂直水平居中的几种方法

原文:http://www.cnblogs.com/qiao915/p/6627982.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!