Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background color not showing for a DIV

Tags:

css

I'm not sure what I'm doing wrong but having trouble applying background color for #content. But it works fine if I set the height value to let say 800px. but I want it to be either auto or 100% as this template will be used throughout the site. any advice would be greatly appreciated.

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

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

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

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

}

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


#contentRight
{
    float:right;
    width:770px; 
    margin:20px 0 0 0;
}

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

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

#footer 
{
    width:980px;
    height:258px;
    margin:auto;
    background:#dadad9 url(images/interior_footer.jpg) no-repeat center top;
}
#footerLeft
{
    width:400px;
    height:50px;       
    float:left;
    padding: 20px 0 0 25px;    
}

#footerRight
{
    width:100px;
    height:50px;       
    float:right;
    padding: 20px 0 0 0;
}
like image 933
user1781367 Avatar asked Feb 19 '13 21:02

user1781367


2 Answers

Set the overflow to auto for #content.

#content {
    width:980px;
    margin:auto; 
    height:auto; 
    background:#fff; 
    overflow:auto;
}
like image 82
j08691 Avatar answered Oct 13 '22 12:10

j08691


The problem is that #content has no content. Since you are using height:100% for the div's height, it will expand to the full height of its parent div (i.e. .content_bg). However, .content_bg has no content either; therefore it is expanding to 100% of zero.

like image 24
JSW189 Avatar answered Oct 13 '22 12:10

JSW189