0

我有这两个带有背景图像的 DIV 标签。

<div class="content_bg">
    <div id="content">
        <div id="contentLeft">   
        </div>
        <div id="contentRight">            
        </div>
    </div>
</div>
<div class="footer_bg">
    <div id="footer">
        <div id="footerLeft">            
        </div>
        <div id="footerRight">           
        </div>
    </div>
</div>

如果我手动设置content的高度,一切看起来都很好,但如果我将其设置为 100% 或 Auto,footer_bg 会重叠在content_bg之上。有人可以建议吗?

/*
====================================================================
Content Area
====================================================================
*/

.content_bg
{
    background:#dadad9 url(images/interior_content_bg_top.jpg) repeat-x center top;

}

#content
{
    width:980px;
    margin:auto;
    height:auto;   
    background:white;     

}

#contentLeft
{
    float:left;
    width:209px; 
    margin-top:50px;   
}


#contentRight
{
    float:right;
    width:770px;     
    font-family: Verdana, Arial, Sans-Serif;
    font-size: 11px;
    line-height:17px;
    border-left:1px solid;
    margin:20px 0 0 0;
}

/*
====================================================================
Footer
====================================================================
*/

.footer_bg
{
    background:#dadad9 url(images/interior_footer_bg.jpg) repeat-x center top;

}

#footer 
{
    width:980px;
    height:258px;
    margin:auto;
    background:#dadad9 url(images/interior_footer.jpg) no-repeat center top;
}
#footerLeft
{
    width:400px;
    height:50px;   
    font-family:Verdana, Arial, sans-serif;
    font-size:11px;    
    line-height:25px;
    float:left;
    padding: 20px 0 0 25px;
    color:#fff;
}


#footerRight
{
    width:100px;
    height:50px;       
    float:right;
    padding: 20px 0 0 0;
}
4

2 回答 2

0

您应该为您的内容接受它的所有父母(包括正文和 html)设置高度 100%。或者只是为内容设置 {min-height: Npx}。您的问题是#content 不知道需要什么高度)

于 2013-02-19T18:44:25.860 回答
0

请参阅小提琴的代码和演示:http: //jsfiddle.net/4Ly7E/1/

演示:http: //jsfiddle.net/4Ly7E/1/embedded/result

注意:由于我没有背景图片,所以我只是假设内容和页脚的边界是边界。

.content_bg
{
    background:#dadad9 url(images/interior_content_bg_top.jpg) repeat-x center top;
    border:1px solid red; /* for visiblity */
    overflow:hidden;

}

.footer_bg
{
    background:#dadad9 url(images/interior_footer_bg.jpg) repeat-x center top;
    border:1px solid teal; /* for visiblity */
    clear:both;
}
于 2013-02-19T18:53:42.873 回答