首页 > 其他 > 详细

没有宽高的情况下实现水平垂直居中

时间:2019-09-17 22:47:50      阅读:131      评论:0      收藏:0      [点我收藏+]

一、

.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>

 

没有宽高的情况下实现水平垂直居中

原文:https://www.cnblogs.com/mengzekun/p/11537679.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!