儿童div 100%高度伸展父div

时间:2013-01-18 20:06:32

标签: css html

我有一个非常简单的场景

父Div(未指定身高)

子div的内容和高度设置为100%。

现在这个子div强制其父级伸展到完整的浏览器窗口。

请指导。

2 个答案:

答案 0 :(得分:1)

在两者上设置位置。

#ParentDiv {
    position:relative;
    height:auto;
}

#ChildDiv {
    position:absolute;
    /* top/left/right force it to dimensions of parent, if needed */
    top:0;
    left:0;
    right:0;
    height:100%;
}

父母会伸展以适应孩子。

答案 1 :(得分:1)

#ParentDiv {
    position:relative;
    height:auto;
}
#ChildDiv {
    position:absolute;
    /* top/left/right force it to dimensions of parent, if needed */
    top:0;
    left:0;
    right:0;
    height:100%;
}

您的ParentDiv高度为AUTO,因此子项强制Parent DIV扩展到浏览器高度的100%。从Parenet DIV中删除auto。你的问题将得到解决。

相关问题