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

垂直水平居中的几种方法

时间:2017-03-27 18:33:08      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:html   ott   margin   页面   vertica   strong   justify   ddl   ica   

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-->

垂直水平居中的几种方法

标签:html   ott   margin   页面   vertica   strong   justify   ddl   ica   

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

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