zoukankan      html  css  js  c++  java
  • css实现垂直水平居中的方法

    html结构:

    <div class="box">
         <div>垂直居中</div>
    </div>

    方法1:display:flex

    .box{
    
        display: flex;
    
        justify-content:center;
    
        align-items:Center;
    
    }

    方法2:绝对定位和负边距

    .box{position:relative;}
    .box div{
    
                position: absolute;
    
                100px;
    
                height: 50px;
    
                top:50%;
    
                left:50%;
    
                margin-left:-50px;
    
                margin-top:-25px;
    
                text-align: center;
    
            }

    方法3:translate

    .box childdiv{
    
                position: absolute;
    
                top:50%;
    
                left:50%;
    
                100%;
    
                transform:translate(-50%,-50%);
    
                text-align: center;
    
            }

    方法4:table-cell

    .box{
    
        display: table-cell;
    
        vertical-align: middle;
    
        text-align: center;        
    
    }

    方法5:偏移量0+margin:auto

    父元素设置相对或绝对定位;要居中的子元素设置绝对定位,所有偏移量为0,外边距为auto:

    .wrap{
    
      positon:relative;
    }
    .center{
    
      positon:absolute;
    
      top:0;bottom:0;left:0;right:0;
    
      margin:auto;
    }
  • 相关阅读:
    DHCP脚本
    7.31
    7.30
    7.26
    7.24
    VLAN与三层交换机
    静态路由配置
    7.17
    四次挥手
    TCP三次握手,四次挥手
  • 原文地址:https://www.cnblogs.com/kunmomo/p/10775747.html
Copyright © 2011-2022 走看看