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;

    待续。。。

  • 相关阅读:
    XJOI网上同步训练DAY2 T2
    XJOI网上同步训练DAY2 T1
    BZOJ 2661 连连看
    HDU 4411 Arrest
    BZOJ 2324 营救皮卡丘
    BZOJ 1927 星际竞速
    BZOJ 3550 Vacation
    XJOI网上同步训练DAY1 T3
    php 类的相互访问
    ThinkPhp5.0_文件上传
  • 原文地址:https://www.cnblogs.com/_error/p/10209958.html
Copyright © 2011-2022 走看看