zoukankan      html  css  js  c++  java
  • 没有宽高的情况下实现水平垂直居中

    一、

    .main {
        width: 300px;
        height: 500px;
        background-color: #50ba8b;
        
    
        position: relative;
       }
     
    .content {
        width: 100px;
        height: 100px;
        background-color: #5b4d4e;
     
    
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        margin: auto;
    }

    二、

    .main {
        width: 300px;
        height: 300px;
        background-color: #50ba8b;
        
    
        position: relative;
    }
     
    .content {
        width: 150px;
        height: 150px;
        background-color: #5b4d4e;
     
    
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    三、

    .main {
        width: 300px;
        height: 300px;
        background-color: #50ba8b;
     
    
        display: flex;
      }
     
      .content {
        width: 150px;
        height: 150px;
        background-color: #5b4d4e;
     
    
        margin: auto;
     }

    四、

    .content {
         width: 150px;
         height: 150px;
         background-color: #5b4d4e;
     
         /*关键代码*/
         display: flex;
         align-items: center;
         justify-content: center;
         margin: auto;
        }
    <div class="content">
        <div>12313</div>   
    </div>
  • 相关阅读:
    【转】ON_COMMAND ON_MESSAGE ON_NOTIFY区别与联系
    Eureka
    application.yml-mysql8
    sprigcloud
    springboot
    maven
    排序算法之基数排序
    排序算法之桶排序
    排序算法之计数排序
    排序算法之堆排序
  • 原文地址:https://www.cnblogs.com/mengzekun/p/11537679.html
Copyright © 2011-2022 走看看