zoukankan      html  css  js  c++  java
  • 关于div水平垂直居中的几种方法

    Dom结构:

    <div class="box">
            <div class="inner">
                123
            </div>
    </div>

    1, 伪元素 加 vertical-align 

           .box {
                width: 300px;
                height: 300px;
                border: 1px solid red;
                text-align: center;
            }
            .box:before{
                content: '';
                height: 100%;
                width: 0;
                display: inline-block;
                vertical-align: middle;
            }
            .inner{
                display: inline-block;
            }

    2, table -ceil

            .box {
                width: 300px;
                height: 300px;
                border: 1px solid red;
                display: table-cell;
                vertical-align: middle;
                text-align: center;
            }    

    3, flex

             .box {
                width: 300px;
                height: 300px;
                border: 1px solid red;
                display: flex;
                justify-content: center;
                align-items: center;
            }
        

    4, transform  

            .box {
                width: 300px;
                height: 300px;
                border: 1px solid red;
                position:relative;
            }
            .inner{
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
            }

    5, absolute + margin:auto  (子元素要设置宽高)

            .box {
                width: 300px;
                height: 300px;
                border: 1px solid red;
                position:relative;
            }
            .inner{
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                width: 100px;
                height: 100px;
                margin: auto;
            }

    6, flex + margin:auto

            .box {
                width: 300px;
                height: 300px;
                border: 1px solid red;
                display: flex;
            }
            .inner{
                margin: auto;
            }
  • 相关阅读:
    zookeeper集群
    Hbase分布式集群
    smokeping Master/Slave安装配置
    CentOS修改163源(转载)
    linux 挂载(转载)
    linux挂载U盘(转载)
    linux下修改path变量(转载)
    tar.gz和rpm安装文件(转载)
    linux ps命令(转载)
    linux free命令(转载)
  • 原文地址:https://www.cnblogs.com/wjyz/p/11389519.html
Copyright © 2011-2022 走看看