Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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
Html 滚动不';不能在多个div中工作_Html_Css_Scroll - Fatal编程技术网

Html 滚动不';不能在多个div中工作

Html 滚动不';不能在多个div中工作,html,css,scroll,Html,Css,Scroll,请帮我做这个 我需要使它滚动,但父div必须是它的高度,例如500px 我知道它在只有父级和子级的情况下工作,但当有多个div时,它是溢出div,滚动不工作。如何做到这一点?这里更新了JSFIDLE的工作示例 增加高度:450pxto#childsparent将为您提供您想要的行为。 首先,我会把溢出:隐藏,但你仍然会有一个非常高的#孩子。您必须限制#childsparent。如果您确定父级的高度为500px,并且#banner的高度为200px,则设置: #childsparent {

请帮我做这个

我需要使它滚动,但父div必须是它的高度,例如500px


我知道它在只有父级和子级的情况下工作,但当有多个div时,它是溢出div,滚动不工作。如何做到这一点?

这里更新了JSFIDLE的工作示例


增加
高度:450px
to#childsparent将为您提供您想要的行为。


首先,我会把
溢出:隐藏#家长
上使用code>,但你仍然会有一个非常高的
#孩子
。您必须限制
#childsparent
。如果您确定父级的高度为500px,并且
#banner
的高度为200px,则设置:

#childsparent {
    [...]
    height:300px; /*or*/
    max-height:300px;
}

如果
#childsparent
#parent
的唯一孩子,那么只需
#childsparent{……身高:100%;}
。否则,如果您不知道横幅的大小,请拿出一些Javascript来进行计算。

谢谢,我知道当我设置px的高度时,解决方案是有效的。。。。当我100%设置在JSFIDLE上时,JSFIDLE也可以工作,但在我的模板中,%似乎不起作用。。。我必须搜索它是什么。。无论如何,感谢它在JSFIDLE中工作,因为您有以像素为单位的父元素,thad浏览器可以设计100%的大小。你也可以添加父元素。最后一句话正是我要找的。。。我需要将height设置为fullfill parent,因为我不会在页面上只有一个可滚动的元素,也不想为每一个新的css height值设置。我应该使用什么javascript?谢谢:)@user3780666在谷歌上搜索jQuery.height(),或者看看
#parent {
    background: #CCC;
    width:200px;
    height:500px;
}

#banner {
    width:200px;
    height: 50px;
    background: #ff0000;
}

#childsparent {
    overflow:scroll;
}
#parent {
        background: #CCC;
        width:200px;
        height:500px;
        overflow: hidden;
    }

#childsparent {
    height: 500px;
    overflow:scroll;
}
#parent {
        background: #CCC;
        width:200px;
        height:550px;
    }

    #banner {
        width:200px;
        height: 50px;
        background: #ff0000;
    }

    #childsparent {
        overflow:scroll;
            height:500px;
    }
#childsparent {
    [...]
    height:300px; /*or*/
    max-height:300px;
}