Here is the snippet (demo available on JsFiddle)
#outer {
display: table;
height: 200px;
width: 100%;
background: gray;
}
#inner {
width: 100%;
background: blue;
max-height: 100%;
}
<div id="outer">
<img id="inner" src="http://jsfiddle.net/img/logo.png">
</div>
The parent element uses display:table
(which is set by a third-party framework), and I set max-height:100%
in the child element for constrain.
However, as can be seen in the demo above (I'm using Chrome 46.0), the child element's height becomes "ZERO" somehow..
When I removed display:table
attributes in the parent element, everything works fine again.
I checked the MDN document for max-height. When mentioning the percentage value of max-height, it says:
The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the percentage value is treated as none.
As I understand for my demo, the #inner
element's containing block is specified explicity to #outer
, so the max-height: 100%
attribute in #inner
will be equivalent to height: 200px
. Is it true? Does anyone have ideas about where I went wrong?
Thanks!