Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将CSS div设置为内容的自动高度_Css - Fatal编程技术网

如何将CSS div设置为内容的自动高度

如何将CSS div设置为内容的自动高度,css,Css,我遇到了这个奇怪的CSS问题。我有两个框,如下面的代码: #mainbox{ width:100%; position:absolute; top:300px; left:0px; min-height: 700px; background-color:#0052b0; display: inline-block; } #contentbox{ width:80%; position:absolute; left:

我遇到了这个奇怪的CSS问题。我有两个框,如下面的代码:

#mainbox{
    width:100%;
    position:absolute;
    top:300px;
    left:0px;
    min-height: 700px;
    background-color:#0052b0;
    display: inline-block;
}

#contentbox{
    width:80%;
    position:absolute;
    left:10%;
    background-color:white;
    border-width:5px;
    border-style:solid;
    border-color:#0052b0;
    min-height:700px;
    top:-50px;
}
#contentbox位于主框内。问题是,当内容高度超过内框限制时,内框将增加其高度,以包装内容。但这种情况不会发生在外盒的主盒上


有人能帮我把这个修好吗?

去掉
位置:绝对
并将其替换为
位置:相对

#contentbox{
width:80%;
left:10%;
position:relative;
background-color:white;
border-width:5px;
border-style:solid;
border-color:#0052b0;
min-height:700px;
top:-50px;
}