开发者

XHTML CSS background not filling entire div

I've got a page that has a background color for the main container, but for some reason, the color ends just below the header div. The page and the CSS validate in the w3 validators, though, and I have no idea why and I've tried several different fixes.

CSS

body{
    margin:0;
    padding:0;
    line-height: 1.5em;
    background-color: #e5e5dc;
    color: #000;
}

#maincontainer{
    background-color: green;
    width: 98%;
    margin: 0 auto;
    border: 1px solid black;
}

#topsection{
    background-color: transparent;
    height: 90px; /*Height of top section*/
}

#logo{
    background-image: url();
    text-align: center;
    margin: 0 auto;
    width: 100%;
}

#contentwrapper{
    float: left;
    width: 100%;
    background-color: transparent;
}

#contentcolumn{
    margin-right: 230px; /*Set right margin to RightColumnWidth*/
}

#rightcolumn{
    float: left;
    width: 230px; /*Width of right column in pixels*/
    margin-left: -230px; /*Set left margin to -(RightColumnWidth) */
    background-color: transparent;
}

#footer{
    clear: left;
    width: 100%;
    background-color: transparent;
    text-align: center;
    padding: 4px 0;
    border-top: 1px solid black;
}

.innertube{
    margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
    margin-top: 0;
}

.error{
    background-image: url("images/misc/scroll.jpg");
    background-position: top left;
    background-repeat: no-repeat;
}

a:link, a:visited{
    color: #000;
    text-decoration: none;
}

a:hover, a:active{
    color: #000;
    text-decoration: underline;
}

EDIT -- Raw html source straight from view source in my browser

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Haven &bull; Login</title> 
    <link href="includes/style.css" rel="stylesheet" type="text/css" /> 


    <script src="includes/jquery.js" type="text/javascript"></script> 
    <script type="text/javascript"> 

    function init()
    {
        var e = document.createElement('script');
        e.src = 'includes/all.js';
        document.getElementById('script_insertion').appendChild(e);
    }
    </script> 
</head> 
<body onload="init();"> 
<div id="script_insertion"></div> 
<div id="maincontainer"> 
    <div id="topsection"> 
        <div class="innertube"> 
            <h1>IMG</h1> 
        </div> 
    </div> 

    <div id="contentwrapper"> 
        <div id="contentcolumn"> 
            <div class="innertube"> 
                <form action="./login.php?mode=login" method="post"> 
                    <table> 
                        <tr> 
                            <td>Username:</td> 
                            <td><input type="text" name="username" id="username" size="10" title="Username" /></td> 
                        </tr> 
                        <tr> 
                            <td>Password:</td> 
                            <td><input type="password" name="password" id="password" size="10" title="Pa开发者_如何学Pythonssword" /></td> 
                        </tr> 
                        <tr> 
                            <td><input type="reset" value="Clear" /></td> 
                            <td><input type="submit" name="login" value="Login" /></td> 
                        </tr> 
                    </table> 
                    <input type="hidden" name="remember" value="true" /> 
                </form> 
                <br /> 
                Don't have an account yet? <a href="./register.php">Register here!</a> 
            </div> 
        </div> 
    </div>  <div id="rightcolumn"> 
        <div class="innertube"> 
            Chat
        </div> 
    </div> 
</div> 
</body> 
</html>


You are floating #contentwrapper which takes it out of the document flow so #maincontainer no longer contains it.

To contain it, you need to give #maincontainer an overflow attribute (auto should work).

FYI, adding borders to your elements are a good way to debug things like this.


If I understand correctly, this is a well addressed question. See CSS 100% height in ie or http://www.tutwow.com/htmlcss/quick-tip-css-100-height/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜