XHTML CSS背景不填充整个div

时间:2011-07-03 03:13:07

标签: css xhtml

我有一个主容器背景颜色的页面,但由于某种原因,颜色在标题div下方结束。然而,页面和CSS在w3验证器中验证,我不知道为什么,我已经尝试了几种不同的修复。

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;
}

编辑 - 直接来自浏览器中的查看源的原始html源

<!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="Password" /></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>

2 个答案:

答案 0 :(得分:2)

您正在浮动#contentwrapper,它会将其从文档流中取出,因此#maincontainer不再包含它。

要包含它,您需要为#maincontainer提供一个溢出属性(auto应该可以工作)。

仅供参考,为元素添加边框是调试此类内容的好方法。

答案 1 :(得分:0)

如果我理解正确,这是一个很好的问题。请参阅CSS 100% height in iehttp://www.tutwow.com/htmlcss/quick-tip-css-100-height/