首页 > 其他 > 详细

水平垂直居中

时间:2020-09-11 16:31:04      阅读:45      评论:0      收藏:0      [点我收藏+]

水平垂直居中

前端常用的盒子布局需要了解
接下来我给大家介绍三种

1.margin和定位

<<<html

  <div class="box">
      <div class="content"></div>
    </div>

<<<js

.box{
  width: 200px;
  height: 200px;
  background-color: red;
  position: relative;
}
.content{
  width: 50px;
  height: 50px;
  background: lightblue;
  position: absolute;
  margin-left: 75px;
  margin-top:75px
 
  
}

2.弹性盒子

<<<html沿用上面的html
<<<js

.box{
  width: 200px;
  height: 200px;
  background-color: red;
display:flex
  justify-content: center;主轴居中
         align-items: center;交叉轴居中
}
.content{
  width: 50px;
  height: 50px;

  
}

3.定位加margin:auto

<<<html沿用上面的html
<<<js

.box{
  width: 200px;
  height: 200px;
  background-color: red;
 position: relative;
  position: absolute;
}
.content{
top:0
bottom:0
left:0
right:0
margin:auto
  
}

水平垂直居中

原文:https://www.cnblogs.com/luckyjiu9/p/13651435.html

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