learningProcess
learningProcess copied to clipboard
我的学习日志(十一)
今天又发现一种新的居中方式,给父元素加相对定位,待居中元素,使用绝对定位
<div class="box">
<div></div>
</div>
css样式
.box {
width: 200px;
height: 200px;
border: 1px solid red;
position: relative;
}
.box div {
width: 50px;
height: 50px;
background: red;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
}
