• css 实现垂直水平居中常用方法


    html

    <div class="outer">
         <div class="inner"></div>
    </div>

    基本样式

    .outer {
        background: #ddd;
         500px;
        height: 500px;
    }
    .inner {
        100px;
       height: 100px;
       background: red;
    }

    一、宽高不固定

    1.display: flex

    .outer {
            display: flex;
            align-items: center;
            justify-content: center; 
    }

    2.absolute + transform

    .outer {
            position: relative;
     } 
    .inner {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
     }

    3.absolute + margin: auto

    .outer {
            position: relative
    }
    .inner {
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
    }

    4.display: table-cell

    .outer {
            display: table-cell;
            vertical-align: middle;
    }
    .inner {
            margin: auto;
    }

    二、宽高固定

    1.text-align + display: inline-block + vertical-align: middle

    .outer {
            text-align: center;
    }
    .outer::after {
            content: '';
            display: inline-block;
            vertical-align: middle;
            height: 500px;
    }
    .inner {
            vertical-align: middle;
            display: inline-block;
    }

    2.absolute + top + left + margin-top + margin-left

    .outer {
            position: relative;
    }
    .inner {
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -50px;
            margin-left: -50px;
    }

    参考:https://github.com/louzhedong/blog/issues/2

  • 相关阅读:
    sqlserver 跟踪标志
    解决ORA-00338,ORA-00312
    oracle SQL性能分析
    高潜力人士和员工
    pymysqlreplication
    Python3操作Excel(写入)
    CentOS7.4 源码安装MySQL8.0
    MySql 时间操作实例
    python+eclipse+pydev开发环境搭建
    MySQL表结构同步工具 mysql-schema-sync
  • 原文地址:https://www.cnblogs.com/bear-blogs/p/10263493.html
Copyright © 2020-2023  润新知