简体   繁体   English

如果容器也具有以百分比表示的最小高度,则以百分比表示的CSS最小高度将不起作用

[英]CSS min-height in percents won't work if container has min-height in percents too

I have a simple markup here: 我在这里有一个简单的标记:

<div class="fixh">

    <div class="outer">
        <div class="inner">
            inner
        </div>

    </div>

</div>

I want to make inner block to have at least 100% height of outer block. 我想使内部块至少具有100%的外部块高度。 If content is bigger than 100%, it should overflow. 如果含量大于100%,则应溢出。 But inner block with min-height:100% won't work! 但是最小高度为100%的内部块将不起作用! Example: http://jsfiddle.net/mBBJM/5378/ 示例: http//jsfiddle.net/mBBJM/5378/

min-height doesn't actually work as well with percentages. min-height实际上不适用于百分比。 What would fix this is just using height:100% here: 解决此问题的方法仅是在此处使用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> 

You should always specify the height and width styles when using the min-height or min-width styles, respectively (or max-height and max-width for that matter). 分别使用min-heightmin-width样式(或与此相关的max-heightmax-width )时,应始终指定heightwidth样式。 Otherwise the CSS doesn't know it needs to change, so it won't. 否则CSS不知道需要更改,因此就不需要更改。

I hope this is what you asked. 我希望这就是你的要求。

http://jsfiddle.net/w9Lghbuw/1/ http://jsfiddle.net/w9Lghbuw/1/

.fixh {
    width: 300px;
    height: 300px;
    background-color: green;
}
.outer {
    width: 100%;
    min-height: 100%;
    background-color: blue;
    height: 100%;
}
.inner {
    color:#fff;
    width: 100%;
    height: 100%;
    line-height: 20px;
    word-break: break-all;
    overflow: auto;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM