[英]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-height
或min-width
样式(或与此相关的max-height
和max-width
)时,应始终指定height
和width
样式。 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.