zoukankan      html  css  js  c++  java
  • 设置盒子水平垂直居中 总结

     
    /*实现方法一:position  transform*/
    .outer{
    position: relative;
    600px;
    height: 400px;
    background-color: aqua;
    }
    .inner {
    position: absolute;
    500px;
    height:300px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: pink;     
    }
     
    /*实现方法二:使用display:flex   align-items:center   justify-content:center*/
    .outer{
    display: flex;
    align-items: center;
    justify-content: center;
    300px;
    height: 200px;
    background-color:  aqua;
    }
    .inner{
    200px;
    height: 100px;
    background-color: blue;
    }
     
     /* 实现方法三:使用position   %   margin */
    .outer{
    position: relative;
    600px;
    height: 400px;
    background-color: aqua;
    }
    .inner{
    position: absolute;
    300px;
    height:200px;
    top: 50%;
    left: 50%;
    margin: -150px 0 0 -250px; /* 外边距为负的自身宽高的一半 */
    background-color: violet;
    }
     
     /* 实现方法四:使用position  0  margin:auto */
    .outer{
    position: relative;
    600px;
    height: 400px;
    background-color: aqua;
    }
    .inner{
    position: absolute;
    300px;
    height:200px;
    top: 0;
    left: 0;
    right:0;
    bottom:0;
    margin: auto; 
    background-color: violet;
    }
     
    /*实现方式五:display:table  display: table-cell;   text-align: center;  vertical-align: middle;*/
    .outer{
    display:table;
    background-color: pink;
    300px;
    height: 200px;
    }
    .inner{
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    }
  • 相关阅读:
    C++类内存分布
    职场人理财之指数基金篇
    职场之殇---有些事情千万不能做
    职场人为什么需要理财
    职场发展之跟对老板有多重要
    职场中怎么做好一个演讲
    多线程如何按指定顺序同步执行
    多线程抢票系统浅析
    Spring Boot进阶系列三
    Spring Boot进阶系列二
  • 原文地址:https://www.cnblogs.com/prospective-zkq/p/9779993.html
Copyright © 2011-2022 走看看