• css 水平垂直居中的几种常用方法


    1. display 方法(最常用的方法)
      display: flex;
      justify-content: center;
      align-items: center;
    2. 定位
      1)固定宽高(100px)
        .parent{
          position: relative;
        }
        .child{
          position: absolute;
          top: 50%;
          left: 50%;
          margin-left: -50px;
          margin-top: -50px;
        }
      2) 有宽高,但不考虑宽高
        .parent{
          position: relative;
        }
        .child{
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          margin: auto;
          height: 50px;
           80px;
        }
      3) 木有具体宽高
        .parent{
          position: relative;
        }
        .child{
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%,-50%);
        }
    3. 控制文本(table-cell)--- margin + vertical-align
      .parent{
        display:table-cell;
        vertical-align: middle;
      }
      .child{
        display: table;
        margin: 0 auto;
      }
    4. 控制文本(table-cell)--- text-align + vertical-align
      .parent{
        display: table-cell;
        text-align: center;
        vertical-align: middle;
      }
        .child{
         80px;
        display: inline-block;
      }
    5. text-align + line-height实现单行文本水平垂直居中
      .test{
        text-align: center;
        line-height: 100px;
      }

  • 相关阅读:
    北京初“探”,还是初“谈”
    hadoop集群安装(多机,非伪集群)
    iOS8下注冊push方式变更
    Linux文件编辑命令具体整理
    HDU 1260
    二叉树遍历(前序、中序、后序、层次、深度优先、广度优先遍历)
    关于Linux静态库和动态库的分析
    JavaScript特效之前进,后退(返回上一级)
    具体解释Hibernate中的事务
    iOS开发
  • 原文地址:https://www.cnblogs.com/qianxiaoniantianxin/p/14666047.html
Copyright © 2020-2023  润新知