我这里有一个简单的标记:
<div class="fixh">
<div class="outer">
<div class="inner">
inner
</div>
</div>
</div>
我想让内部 block 的高度至少为外部 block 的 100%。如果内容大于 100%,它应该溢出。但是具有 min-height:100% 的内部 block 将不起作用! 例子: http://jsfiddle.net/mBBJM/5378/
最佳答案
min-height
实际上并不能很好地处理百分比。解决此问题的方法是在此处使用 height:100%
:
.fixh {
width: 300px;
height: 300px;
background-color: green;
}
.outer {
width: 100%;
height: 100%;
min-height: 100%;
background-color: blue;
}
.inner {
width: 100%;
height: 100%;
min-height: 100%;
background-color: gray;
}
<div class="fixh">
<div class="outer">
<div class="inner">
inner
</div>
</div>
</div>
在使用 min-height
或 min-width
时,您应该始终指定 height
和 width
样式样式(或 max-height
和 max-width
就此而言)。否则 CSS 不知道它需要更改,所以它不会。
关于html - 如果容器也有以百分比表示的最小高度,则以百分比表示的 CSS 最小高度将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27565864/