zoukankan      html  css  js  c++  java
  • 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;
      }

  • 相关阅读:
    python__基础 : 类属性,类方法,静态方法
    python__基础 : 类的继承,调用父类的属性和方法
    python__基础 : 类的__init__,__str__,__del__方法
    Python__关于列表的引用 以append操作为例
    HTML5 Canvas 绘制图片不显示的问题
    MySQL 查询排除指定字段、自定义变量、动态执行SQL
    .Net系列 Transaction 事务
    Redis 基本操作
    C# 数值计算、转换
    详解.NET IL代码
  • 原文地址:https://www.cnblogs.com/qianxiaoniantianxin/p/14666047.html
Copyright © 2011-2022 走看看