一.div内元素垂直水平居中
code:https://codepen.io/piedpiperr/pen/zmYoRx
- 利用flex:
.iteams_center{
display:flex;
justify-content:center;
align-items:center;
}
- 绝对定位方式
<div class="wp">
<div class="box size">123123</div>
</div>
.wp {
border: 1px solid red;
width: 300px;
height: 300px;
position: relative;
}
.box {
width: 100px;height: 100px;
background: green;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
网友评论