0

我想为页面内容设置背景。带有背景图像的 div 具有class=history. “历史”和历史本身之上的所有 div 都将高度设置为 100%。但是,“历史” div 没有得到正确的高度。

下面是代码示例。我可能会遗漏一些相关细节,但一旦找到解决方案就会添加它们。另请参阅实时页面

CSS:

html, body {
    height: 100%;
    background: url(cream_dust.png) repeat 0 0;
}

的HTML:

<html>
<body class="page page-id-41 page-child parent-pageid-8 page-template-default logged-in admin-bar">
<div class="wrapper-for-footer">
<div id="page" class="hfeed site">
<div id="main" class="site-main">
<div id="primary" class="content-
4

2 回答 2

2

An element that is set to height: 100% will only take up 100% of the vertical space of its parent. If there's an element somewhere between history and body that doesn't have a height, then it won't be as tall as you're expecting.

The majority of the history element is floated content, so it has collapsed to only contain the non-floated content.

Add a clearfix to the history element.

overflow: hidden

or

.history {
    zoom: 1; // fix for IE
}

.history:after {
    content: ' ';
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
于 2012-12-26T01:06:30.730 回答
0

您可能需要添加position:absolute;div您尝试给予 100% 高度的内容。

编辑:您需要添加position:absolute;history div

于 2012-12-26T00:43:28.820 回答