粘性页脚布局有问题

时间:2011-08-07 07:01:26

标签: css

我正在尝试使用粘性页脚和页面宽度的页眉进行网站布局。内容div应该是960px宽,高度应该从标题的底部到页脚的顶部。它应该始终至少是这个高度。我现在面临的一个问题是,我可以将内容div作为其内容的高度,或者扩展到包装div,在页面结束的位置下方。

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-    strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <style>
html{
height: 100%;
min-height: 100%;
}

body{
min-height: 100%;
width: 100%;
height:100%;
}

#wrap{
height:auto;
height:100%;
min-height:100%;
position:relative;
margin:auto;
}

#header{
background: blue;
height: 152px;
}

#content{
background: #555;
min-height: 100%;
margin: 0 auto;
width: 960px;

}

#footer{
margin-bottom: 41px;
height: 59px;
background: red;
position:absolute;
width:100%;
bottom:0;
}
</style>

</head>
<body>
    <div id ='wrap'>
        <div id='header'>
        </div>
        <div id='content'>
        </div>
        <div id='footer'>
        </div>
    </div>
</body> 

1 个答案:

答案 0 :(得分:1)

您应该对#wrap下的所有元素使用position:relative,因此它们将相对位于彼此之下,并且将高度设置为100%无效。

您已将页脚位置设置为绝对位置,这会使其粘贴到页面顶部