zoukankan      html  css  js  c++  java
  • 块元素垂直水平居中的方法

    1、使用flex

    .parent {
        height: 600px;
        border: 1px solid red;
        
        display: flex; 
        justify-content: center;
        align-items: center;
    }
    .child {
        border: 1px solid green;
           300px;
    }

    2、使用transform

    .parent{
      height: 600px;
      border: 1px solid red;
      position: relative;
    }
    .child{
      border: 1px solid green;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
    }

    3、使用margin-top -一半的高度

    .parent{
      height: 600px;
      border: 1px solid red;
      position: relative;
    }
    .child{
      border: 1px solid green;
       300px;
      height: 100px;
      position: absolute;
      top: 50%;
      left: 50%;
      margin-left: -150px;
      margin-top: -50px;
    }

    4、使用绝对布局absolutemargin:auto

    .parent{
      height: 600px;
      border: 1px solid red;
      position: relative;
    }
    .child{
      border: 1px solid green;
      position: absolute;
       300px;
      height: 200px;
      margin: auto;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
    }
  • 相关阅读:
    传纸条
    金明的预算方案
    矩阵取数
    能量项链
    选择客栈
    过河
    乌龟棋
    逢低吸纳
    三角形牧场
    多米诺骨牌
  • 原文地址:https://www.cnblogs.com/momo798/p/5985049.html
Copyright © 2011-2022 走看看