css水平垂直居中(绝对定位居中)

使用绝对定位有个限制就是父集必须设置一个固定的高度。

首先HTML

 <div id="box">
<div class="child"></div>
</div>

CSS

 #box {
position: relative;
height: 500px;
background: red;
}
.child {
width: 100px;
height: 100px;
background: blue;
margin: auto;
position: absolute;
top:;
right:;
bottom:;
left:;
}

示例图:

css水平垂直居中(绝对定位居中)

上一篇:Vue.js 服务端渲染业务入门实践


下一篇:255. Verify Preorder Sequence in Binary Search Tree