Skip to content

::before with position: absolute incorrectly positioned at viewport origin when parent element has zero size #8302

@twhlynch

Description

@twhlynch

Summary

When an element has no size (in my example, no content + inline positioning), it is positioned based on the viewport offset rather than its parent element.

Operating system

macOS

Steps to reproduce

Minimal snippet to reproduce the bug

<style>
    span {
        position: relative;
    }
    span::before {
        content: "c";
        position: absolute;
        top: 0;
        left: 0;
    }
</style>
a<span></span>b a<span> </span>b

The first span has no content and is zero size; the second has a space, making it non-zero-sized.

Expected behavior

The ::before element should be positioned based on its parent element, even when the parent has zero size.

Chrome places it where the element is

Actual behavior

The ::before element is placed at the viewport origin when the parent has zero size.

Ladybird places it at the viewport origin

URL for a reduced test case

https://refined-github-html-preview.kidonng.workers.dev/twhlynch/ladybird/raw/refs/heads/zero-size-parent-pseudo-element-positioning/Tests/LibWeb/Screenshot/input/css-zero-size-parent-with-pseudo-element.html

HTML/SVG/etc. source for a reduced test case

N/A

Log output and (if possible) backtrace

N/A

Screenshots or screen recordings

No response

Build flags or config settings

No response

Contribute a patch?

  • I’ll contribute a patch for this myself.

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