-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
documentHeight
calculation not considering bottom margin/padding and overflow content
#13343
Comments
This issue hasn't been updated in awhile. @jridgewell Do you have any updates? |
1 similar comment
This issue hasn't been updated in awhile. @jridgewell Do you have any updates? |
This issue hasn't been updated in awhile. @jridgewell Do you have any updates? |
Is this still an issue? I wonder if this was related to quirks mode. |
I just tried again and can still reproduce. If I simply set the height of the iframe to whatever the |
Just read the original issue, makes sense. #12229 assumed it "should be a no-op for docs which @jridgewell Let's get this in the fix-it. |
Why aren't we just using |
We should use |
|
Doing some checks:
|
So what is it that we want here? This entire thing confuses the hell out of me. |
My understanding is that we are not simply using Maybe a better way to define the desired
Tried my best to put these into words... But I don't know how we can do this in a nice way programmatically. As I mentioned in the issue description at the top, Peter's "content height" algorithm doesn't really include bottom padding and margin on the |
I'm not aware of a good way to do that either. We could use I think AMP developers should be able to restructure overflowing child elements such that they're recognized by our "content height" calculation. Is this possible for your use case, Su? Also, note that
WDYT about using the formula above in OP (and leaving problem (2) unsolved)? getContentHeight() {
const scrollingElement = this.getScrollingElement();
const rect = scrollingElement.getBoundingClientRect();
const style = getComputedStyle(scrollingElement);
return rect.height + parseInt(style.marginTop, 10) + parseInt(style.marginBottom, 10);
} |
Sounds good. We can document the overflow caveat in a best practices doc somewhere for developers. |
We used to calculate the
documentHeight
value usingscrollHeight
onscrollingElement
, but we recently changed the formula in #12229 to use the height of the bounding client rect of<body>
plus any margin/padding on any element between the top of the viewport and the the top of<body>
:amphtml/src/service/viewport/viewport-binding-natural.js
Line 205 in 7b211a1
This fixes the issue when the actual document content height is smaller than the viewport height, in which case
scrollHeight
is always set to the height of the viewport, resulting in incorrect document height.However, with the following AMP HTML:
The new formula doesn't result in the same number as the original formula:
There are two problems:
The new formula is not taking the
margin-bottom
andpadding-bottom
of the<html>
element into consideration. 956 = 944 (bounding client rect height of<body>
) + 12 (top margin and border of<html>
), but with the padding, border and margin at the bottom of<html>
, the number should really be 956 + 20 + 2 + 10 = 988.The new formula is not taking overflow content into consideration.
.container
is set to have a fixed height of100px
, while its only child.foo
has a top and bottom margin of800px
. As a result, the bottom margin of.foo
overflows its parent.container
. In the old formula,scrollHeight
of<html>
actually includes the overflow margin, but the new formula doesn't, as the bounding client rect of<html>
(or<body>
) doesn't include the overflow margin in descendent nodes.For problem 1, I managed to fix it with the following formula:
The bounding client rect of
<html>
includes padding and border of<html>
, but not margin, so including the top and bottom margin should give the correct result. However, this doesn't fix problem 2. Not sure how we should approach problem 2 without re-implementing too much of the layout engine.@peterjosling @jridgewell @raywainman @choumx
The text was updated successfully, but these errors were encountered: