码迷,mamicode.com
首页 > Web开发 > 详细

子元素位于父元素中央 css实现

时间:2019-11-25 20:44:45      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:abs   height   margin   absolute   nsf   position   osi   display   ott   

wrap .box{

width: 200px;
height:200px;
background: pink;

// 方案1
position: absolute;
top:0;
left:0;
right:0;
bottom:0;
margin: auto;

//方案2
position:absolute;
top:50%;
left:50%;
transfrom:translate(-50%,-50%);
}

//方案3

wrap{

width:500px;
height: 500px;
background: gray;

display: flex;
justify-content: center; // 主轴水平居中
align-items: center; // 侧轴居中
}

子元素位于父元素中央 css实现

标签:abs   height   margin   absolute   nsf   position   osi   display   ott   

原文地址:https://www.cnblogs.com/mengzhongfeixue/p/11929890.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!