zoukankan      html  css  js  c++  java
  • 关于垂直居中

    table 方式

    .parent {
        display: table-cell;
    vertical-align: middle; } .child { margin: auto; }

    translate + 绝对定位:

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

    绝对定位+四个方向置0

    .parent{
        width: 200px;
        height: 200px;
        position: relative;
    }
    .child{
        width: 100px;
        height: 100px;
        margin: auto;  
        position: absolute;  
        top: 0; 
        left: 0; 
        bottom: 0; 
        right: 0; 
    }

     ::after + inline-block :

    .parent{
        /***/
    }
    .parent::after{
        content: '';
        width: 0;
        height: 100%;
        display: inline-block;
        vertical-align: middle;
    }
    .child{
        display: inline-block;
    }

    flex 布局

    .parent {
        display: flex;
        align-items: center;
    }
    .child {
        /**/
    }

    ---- 移动端 文字在容器内垂直居中  安卓 line-height 不居中----

    传统写法是 令 line-height 与 height 相等即可,但是在安卓浏览器里文字会偏上,无法居中。网上大神分析原因大致是 Android 对文字的渲染高度不同。我们可以采取 flex 的方式来解决

    display: flex;
    align-items: center;

    待续。。。

  • 相关阅读:
    数列分段divide
    精度计算(保留几位小数)
    洛谷P1119灾后重建
    暴雨rain
    石子游戏stone
    化学家chemist
    【ybtoj】【质数和约数】合并集合
    【ybtoj】【质数和约数】质数距离
    【ybtoj】【质数和约数】不定方程
    【再见OI】9.23模拟总结
  • 原文地址:https://www.cnblogs.com/_error/p/10209958.html
Copyright © 2011-2022 走看看