CSS盒子高度不会延伸到100%

时间:2013-07-07 13:32:59

标签: html css height

每个人都有一个盒子放在盒子里。我希望左列拉伸到全高。 所以问题是左列不会伸展到内容框的整个高度。

这是HTML

<div id="realBody">
    <div id="bigBox">
        <div id="contentBox">
            <div id="rightColumn" style="height:600px;">

            </div>

            <div id="leftColumn">

            </div>
        </div>
    </div>
</div>

CSS

@CHARSET "UTF-8";

body                {
                    height: 100%;
                    margin:0px;
                    overflow:hidden;
                    background:url(../image/bg.jpg);
                    background-repeat:repeat-x;
                    background-position:center;
                    background-color:black;
                    font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
                    }



 #bigBox                {
                        width:1000px;
                        height:auto;
                        overflow:auto;
                        margin:40px auto 20px auto;
                        padding:10px;
                        }

#realBody           {
                    position:absolute;
                    z-index: 5;             
                    overflow:auto;
                    height:100%;width:100%; 
                    }

#contentBox         {
                    border-top:solid 10px #e1e1e1;
                    border-bottom:solid 10px #d1d1d1;
                    margin-top:10px;
                    background-color:white; 
                    overflow:auto;
                    height: auto;
                    box-shadow:0px 0px 20px black;
                    }



#leftColumn         {
                    position:relative;
                    width:300px;
                    padding:10px;
                    height:100%;
                    box-shadow:0px 0px 20px black;
                    background-color:#e3e3e3;
                    z-index:6;
                    }

#rightColumn        {
                    position:relative;
                    float:right;
                    width:650px;
                    padding:10px;
                    z-index:4;
                    }

2 个答案:

答案 0 :(得分:0)

将HTML的高度设置为height: 100%; :)

您需要将每个父元素的元素高度设置为100%

Fiddle.

<强> CSS:

@CHARSET"UTF-8";
 html, body {
    height: 100%;
    margin:0px;
    overflow:hidden;
    background:url(../image/bg.jpg);
    background-repeat:repeat-x;
    background-position:center;
    background-color:black;
    font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
#bigBox {
    width:1000px;
    height:100%;
    overflow:auto;
    margin:40px auto 20px auto;
    padding:10px;
}
#realBody {
    position:absolute;
    z-index: 5;
    overflow:auto;
    height:100%;
    width:100%;
}
#contentBox {
    border-top:solid 10px #e1e1e1;
    border-bottom:solid 10px #d1d1d1;
    margin-top:10px;
    background-color:white;
    overflow:auto;
    height: 100%;
    box-shadow:0px 0px 20px black;
}
#leftColumn {
    position:relative;
    width:300px;
    padding:10px;
    height:100%;
    box-shadow:0px 0px 20px black;
    background-color:#e3e3e3;
    z-index:6;
}
#rightColumn {
    position:relative;
    float:right;
    width:650px;
    padding:10px;
    z-index:4;
}

答案 1 :(得分:0)

这是另一个Fiddle

/* Set height: 100% for both of body, html */
html, body {
    height: 100%;
}
body {
    margin:0px;
    overflow:hidden;
    background:url(../image/bg.jpg);
    background-repeat:repeat-x;
    background-position:center;
    background-color:black;
    font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
#bigBox {
    width:1000px;
    height:auto;
    overflow:auto;
    margin:40px auto 20px auto;
    padding:10px;
}
#realBody {
    position:absolute;
    z-index: 5;
    overflow:auto;
    height:100%;
    width:100%;
}
#contentBox {
    border-top:solid 10px #e1e1e1;
    border-bottom:solid 10px #d1d1d1;
    margin-top:10px;
    background-color:white;
    overflow:auto;
    height: auto;
    box-shadow:0px 0px 20px black;
    position: relative;
}
#leftColumn {
    position:absolute; /* User position:absolute; */
    left: 0;           /* Set left: 0; */      
    top: 0;            /* Set top: 0; */
    width:300px;
    padding:10px;
    height:100%;
    box-shadow:0px 0px 20px black;
    background-color:#e3e3e3;
    z-index:6;
}
#rightColumn {
    position:relative;
    float:right;
    width:650px;
    padding:10px;
    z-index:4;
}