zoukankan      html  css  js  c++  java
  • css的垂直居中常用几种方法

    父元素样式

    .father{
                 100%;
                height: 100%;
                margin: 0;
                padding: 0;
    }
    

    子元素垂直居中方法一

    子元素要是块
    relative/absolute+top50%+maringTop(-div一半高度)

    .son{
                  400px;
                height: 400px;
                background: orange;
                margin: 0 auto; /*水平居中*/
                position: relative;
                top: 50%; /*偏移*/
               margin-top:-200px;
    }
    

    子元素垂直居中方法二

    relative/absolute+top50%+translateY(-50%)一半高度
    子元素要是块

    .son{
                 400px;
                height: 400px;
                background: orange;
                margin: 0 auto; /*水平居中*/
                position: relative;
                top: 50%; /*偏移*/
                transform: translateY(-50%);
    }
    

    子元素垂直居中方法三

    给父元素设置内容

    body {
              display: flex;
              align-items: center; /*定义body的元素垂直居中*/
              justify-content: center; /*定义body的里的元素水平居中*/
          }
    
  • 相关阅读:
    hashlib模块
    logging模块
    Python的富比较方法
    格式化符号说明
    __str__与__repr__区别
    2014-07-18 10:25

    2014-07-17 17:04
    2014-07-17 16:44
    2014-07-16 15:54
  • 原文地址:https://www.cnblogs.com/liuXiaoDi/p/12906811.html
Copyright © 2011-2022 走看看