Skip to content

Margin Collapsing can cause not-visible shifts to elements #119

@mmocny

Description

@mmocny

Margin collapsing can sometimes turn a small shift on a child element into a large shift on a parent/sibling element.

For example:

Visually-- only the two colored elements shifted.

But, actually the body element experienced "margin collapsing", which technically meant the whole body shifted down.

(It's not so much that the shift didn't happen, technically it did, but it's not exactly producing the result we would expect. In the example, only the two child elements visually shift.)

Screenshot 2023-03-31 at 12 09 50 PM

However, if you apply e.g. a Border to the body, that disabled margin-collapsing and the (more visually) correct CLS is reported.

Screenshot 2023-03-31 at 12 14 32 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions