zoukankan      html  css  js  c++  java
  • DIV居中的几种方法

    DIV居中的几种方法

     

    1.

    1 body{  
    2 text-align:center;  
    3 } 

    缺点:body内所有内容一并居中

    2.

    .center{
    position: fixed;
    left: 50%;
    }

    缺点:需要设置position属性,网页复杂时容易扰乱页面布局,而且只是元素的起始位置居中

    3.

    1 .center{
    2 500px;
    3 margin: 0 auto;
    4 }

    缺点:需要设置div宽度

    4.

    1 .center {  
    2   display: -webkit-flex;  
    3   -webkit-justify-content: center;  
    4   -webkit-align-items: center;  
    5  }  

    缺点:需要支持Html5

    5.

    复制代码
    1     .center {
    2         position: absolute;
    3         top: 50%;
    4         left: 50%;
    5         -ms-transform: translate(-50%,-50%);
    6         -moz-transform: translate(-50%,-50%);
    7         -o-transform: translate(-50%,-50%);
    8         transform: translate(-50%,-50%); 
    9     }
    复制代码

    缺点:需要支持Html5

    6.

    1     margin: auto;
    2     position: absolute;
    3     left: 0;
    4     right: 0;

     7.parent{

    justify-content:center;

    align-items:center;

    display:_webkit-flex;

    }

  • 相关阅读:
    053(四十四)
    053(四十三)
    053(四十二)
    053(四十一)
    053(四十)
    053(三十九)
    053(三十八)
    053(三十七)
    053(三十六)
    【leetcode❤python】231. Power of Two
  • 原文地址:https://www.cnblogs.com/justuntil/p/7447355.html
Copyright © 2011-2022 走看看