Update: After receiving clarification from @onkar-ruikar, I realized that my original problem was quite misunderstood. While I still haven't figured out how to properly handle the cyclic dependencies issue, I decided to address it separately. As a result, I have marked this problem as solved and created a follow-up question here: Dealing with cyclic dependencies of percentage sized boxes css (specifically how to get a max-height)
The main issue I'm facing is related to the improper functioning of max-height in grid elements. Essentially, I have a grid element with a flexible size containing an iframe. My goal is to scale the iframe to its full size while ensuring that a surrounding div adapts to the iframe size, with a maximum size equal to the grid element, allowing for scrolling when necessary. However, I am encountering difficulties with the max-height property not behaving as expected. To illustrate this problem, I have created a sample scenario in this jsfiddle:
In the provided code snippet, different outcomes are observed when using "height: 100%;" versus "max-height: 100%;" in #grid1:
#grid0 {
display: grid;
grid-template-rows: 50px;
grid-template-columns: 200px;
height: 500px;
}
#grid1 {
height: fit-content;
max-height: 100%;
background: blue;
/* it works using height instead of max-height
height: 100%;
*/
}
#out {
height: auto;
max-height: 100%;
overflow: hidden;
background: purple;
width: 150px;
}
#large {
height: 100px;
width: 100px;
background: red;
}
<div id='grid0'>
<div id='grid1'>
<div id='out'>
<div id='large'>
</div>
</div>
</div>
</div>
By comparing the results between these two approaches, specifically by uncommenting the "height: 100%;" line in the CSS for #grid1, discrepancies can be noted. Interestingly, while inspecting #grid1 in Firefox, the height appears correctly even with max-width set, indicating a rendering inconsistency.
I attempted to introduce an additional container around #out, adjusting its height to auto and max-height to 100%, along with setting #grid1's height to 100% for resolution, suspecting the issue may be related to "fit-content". Unfortunately, this solution did not yield the desired outcome...
If anyone has suggestions or insights on how to overcome this challenge, I would greatly appreciate any input!