zoukankan      html  css  js  c++  java
  • div上下左右居中几种方式

    1、绝对定位(常用于登录模块)
    备注:前提条件div需要有宽高

    #html
    <div class="box"></div>
    #css
    .box{
    position:absolute/fixed;
    left:0;
    right:0;
    top:0;
    bottom:0;
    margin:auto;
    }
    

    2、margin负值
    备注:前提条件div需要有宽高

    #html
    <div class="box"></div>
    #css
    .box{
    200px;
    height: 200px;
    position: absolute;
    left:50%;
    top:50%;
    margin-left:-100px;
    margin-top:-100px;
    }

    3、css3 transform
    备注:用于不确定当前div的宽度和高度

    #html
    <div class="box"></div>
    #css
    .box{
    position: absolute;
    left:50%;
    top:50%;
    transform: translate(-50%, -50%);
    }

    4、flex 布局方式

    #html
    <div class="box">
    <div class="child">child</div>
    </div>
    #css
    .box{
    display:flex;
    align-items:center;
    justify-content:center;
    }
    

     

    5、table-cell 方式

    #html
    <div class="box">
    <div class="child">child</div>
    </div>
    #css
    .box{
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    }
    

      

  • 相关阅读:
    Pandas获取本地csv文件到内存中
    波士顿房价数据集可视化
    tensorflow之数据集调用(波士顿房价数据集)
    查单词
    censoring
    字符串大师
    Parity game
    前缀和
    String
    Seek the Name, Seek the Fame
  • 原文地址:https://www.cnblogs.com/sweeeper/p/11846848.html
Copyright © 2011-2022 走看看