DEV Community

Discussion on: How would you go about detecting the height of content within an iframe?

 
alohci profile image
Nicholas Stimpson

Yes, yes and yes. MDN is slightly lacking in this area, and you really need to read the actual specs.

First, on display:contents, I specfically said the "computed value" because the relevant spec says "The root element’s display type is always blockified. Additionally, a display of contents computes to block on the root element."

Second, on the matter of margins, it differs depending on whether we're dealing with the root element or not. Step 4 of the rules for the calculation of the scrollHeight say that the root element is treated specially. It says that "If the element is the root element and document is not in quirks mode return max(viewport scrolling area height, viewport height)." The calculation of the viewport scrolling area is quite detailed but an abbreviation for the bottom edge says it's "The bottom-most edge of the bottom edge of the initial containing block and the bottom margin edge of all of the viewport’s descendants' boxes." (my emphasis) Note that the initial containing block itself doesn't have margins.

If you compare that with the rules for other elements, then you see that the margins of the target element are not counted, but the margins of its descendant boxes are counted.

Thread Thread
 
joshuatz profile image
Joshua Tzucker

Thanks for the clarification! Much appreciated since the specs can be rather dense and hard to understand at a glance.