css - 如何让子div扩展到父div

标签 css

您好,我在尝试让我的子 div 扩展到它所在的父 div 的高度时遇到了问题。

这是父div的css

#wrapper #content {
    border: 1px ridge #999;
    height: auto;
    min-height: 1000px;
    width: 1100px;
    margin-top: 40px;
    margin-right: auto;
    margin-bottom: 30px;
    margin-left: auto;
    float: left;
}

这是子div的css

.tab_container {
    clear: both;
    width: 100%;
    border-right: 1px ridge #999;
    margin-bottom: 20px;
    height: 100%;
}

有什么想法吗?

最佳答案

您可以使用以下样式来完成:(受此问题启发:CSS - Expand float child DIV height to parent's height)

#content {
    border: 1px ridge #999;
    height: auto;
    min-height: 1000px;
    width: 1100px;
    margin-top: 40px;
    margin-right: auto;
    margin-bottom: 30px;
    margin-left: auto;
    float: left;
    position: relative; /* added */
    width: 100%; /* added */
}

.tab_container {
    border: 1px ridge orange; /* added */
    clear: both;
    width: 100%;
    border-right: 1px ridge #999;
    margin-bottom: 20px;
    height: 100%;
    position: absolute; /* added */
}

Fiddle here

关于css - 如何让子div扩展到父div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8113238/

相关文章:

html - 如何更改此导航栏的颜色和背景?

javascript - 多个弹出模态框

javascript - 更改背景图像 jQuery

jquery - 删除或添加禁用到 iCheck radio 输入

javascript - 选择的 jquery 脚本不工作

javascript - 使用 HTML、CSS 和 jQuery 的主从关系

html - 为什么 <hr/> 的颜色没有变化?

css - 更改 bootstrap.css 中的段落字体大小

html - 溢出:指定 TD 和 TH 宽度时隐藏不起作用

javascript - 单页 Angular 应用程序中的 body 填充