有一段时间我是错误的,所以也许别人觉得它很有用。
HTML:
<div class="parent-center-center-1">
<div class="parent-center-center-2">
<div class="parent-center-center-3">
<div class="child-center-center">
Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes Content for New Div Tag Goes
</div>
</div>
</div>
</div>
CSS:
.parent-center-center-1 {
background-color: #F00;
position: absolute;
width: 100%;
height: 100%;
}
.parent-center-center-2 {
background-color: #090;
position: relative;
width: 100%;
height: 100%;
display: table;
text-align: center;
}
.parent-center-center-3 {
background-color: #FF0;
position: relative;
display: table-cell;
vertical-align: middle;
}
.child-center-center {
background-color:#F00;
display: inline-block;
}
这是关于它,只是复制和粘贴。如果你将孩子放在“容器”中,它也有效。