使用CSS垂直居中div
我目前正在一个wordpress网站上工作,我想使用CSS将我的页面包装置于中心位置。我尝试在这个网站上实现方法3,但没有成功 地点: 我使用两个不同的div,一个id为flotter,另一个id为page wrap。我的css看起来像这样使用CSS垂直居中div,css,Css,我目前正在一个wordpress网站上工作,我想使用CSS将我的页面包装置于中心位置。我尝试在这个网站上实现方法3,但没有成功 地点: 我使用两个不同的div,一个id为flotter,另一个id为page wrap。我的css看起来像这样 #floater { float: left; height: 50%; margin-bottom: -481px; } #page-wrap { clear: both; color: white; width: 1594px; height: 962
#floater { float: left; height: 50%; margin-bottom: -481px; }
#page-wrap { clear: both; color: white; width: 1594px; height: 962px; margin: auto; position: relative; }
我还想指出,在我的pagewrap div中,我有很多其他div来构建我的设计,如果这对结果有任何影响,它们也会左右浮动
链接到JSFIDLE:试试看
#floater{
margin-top: 25%;
}
或
如果您知道它的高度,最简单的解决方案是:
#page-wrap { position: absolute; height: 900px; top: 50%; margin-top: -450px; }
基本上它说,;将其顶部定位在50%,并将其高度减半,使div的中心居中。创建一个jsfiddle,用一个示例说明您的示例,我希望它能起作用。可能的副本。在SO和其他网站上,这些问题的数量多得可笑。
#page-wrap { position: absolute; height: 900px; top: 50%; margin-top: -450px; }