【发布时间】:2012-08-22 21:16:07
【问题描述】:
如何将父容器垂直居中对齐到具有position:relative 的画布?父容器有一个带有position:absolute 的子元素。子元素已定位在父容器的中心。
这是一个sn-p:
.container {
position: relative;
width: 300px;
height: 300px;
background-color: red;
margin: auto;
}
.item {
position: absolute;
width: 100px;
height: 100px;
background-color: blue;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
<div class="container">
<div class="item"></div>
</div>
【问题讨论】:
标签: css alignment css-position center