【发布时间】:2013-12-20 01:24:09
【问题描述】:
在下面的小提琴中:
我有一个黄色的内容区域,它的 min-height 设置为 100% - 它是所有页面的背景 div,应该至少占据可用高度的 100%。如果有溢出,它会垂直扩展。
然后,在那个黄色容器中,我有另一个子 div(红色),我想占用与其父级一样多的垂直空间。看来我无法设置height,因为父元素只有min-height,并且在红色元素上设置最小高度也不起作用。
所以现在,黄色的行为符合我的意愿,但红色没有扩大。如何仅使用 CSS 来实现?
CSS:
.browser {
background-color: blue;
height: 600px;
width: 200px;
position: relative;
}
.innercontent {
min-height: 100%;
background-color: red;
width: 100%;
color: white;
padding: 2px;
}
.content {
background-color: yellow;
width: 100%;
min-height: calc(100% - 30px);
}
.footer {
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
background-color: orange;
height: 20px;
}
HTML:
<div class="browser">
<div class="content">
<div class="innercontent">
This is the problem - I need this to take up 100% of the remaining yellow space, without setting the parent element's 'height' - only min-height is specified in the parent because I need to make sure that it takes up 100% of the height at least, but allow it to extend vertically if there's any overflow.
</div>
should not see any yellow
</div>
<div class="footer"></div>
</div>
【问题讨论】:
标签: css