虽然这看起来很像很多已存在的帖子,但我找不到解决方案。在没有固定宽度或高度的div中居中放置内容
我有以下HTML:
<div class="outer-zone">
<div>
Outer zone.
</div>
<div class="inner-zone">
Inner zone here...
</div>
</div>
和相应的类,如下所示:
.outer-zone {
background-color : navy;
color : whitesmoke;
width : 90%;
height: 50%;
text-align: center;
margin-left: auto;
margin-right: auto;
}
.inner-zone {
background-color : deepskyblue;
color : navy;
width : 75%;
height : 40%;
margin-left: auto;
margin-right: auto;
}
我想实现是有outer-zone
格,居中(垂直和水平)在页面中,和inner-div
,集中在外部div。
到目前为止,我发现的所有内容都是如何在固定高度的div内对齐内容。我想保留这些div宽度和高度。
结果到目前为止,看起来是这样的:
(拖动图片有点要注意底部的空格)
据我所知,你会需要一个固定的像素,而不是百分比(我只是在周五做这个工作,找不到工作pecentage周围很简单) –
我觉得@ RUJordan是正确的。 margin-left:auto需要固定的宽度。 – Liam
它已经水平居中,我的问题实际上是垂直居中。 – VasileF