使位置居中的元素:绝对;应用通过使用两个嵌套元素(
demo).
>第一个元素绝对定位于将其置于所有其他元素之上
>第二个元素就像你期望的那样:使用margin:0 auto;以中心为中心.
HTML:
This is a modal window being centered.
CSS:
.outer-div {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 13;
/*
* Setting all four values to 0 makes the element as big
* as its next relative parent. Usually this is the viewport.
*/
}
.inner-div {
margin: 0 auto;
width: 400px;
background-color: khaki;
}