Skip to content

<img> elements with width and height attributes have incorrect aspect ratio with height: auto; max-height: [...] #32776

Closed

Description

@valadaptive

Describe the bug:

When an <img> element has width and height attributes, a height: auto CSS property, and a max-height: [some value] CSS property, it should maintain its intrinsic aspect ratio. However, it does not in Servo:

Firefox Servo
image image

This is probably due to some suspicious clamping performed in the replaced element sizing algorithm--the CSS spec says that if the tentative width falls outside the range of min-width and max-width (or the same for the height), the layout calculation should be redone with the clamped values. The re-calculation allows the aspect ratio to be calculated correctly. However, the current code seems to only perform the layout calculation once and then clamp the width and height afterwards.

To Reproduce:

Test case HTML
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>CSS image height: auto test</title>
    <style>
        img {
            height: auto;
            max-width: 240px;
        }
    </style>
</head>
<body>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAYCAMAAAClZq98AAABZGlDQ1BpY2MAAHjalZEzoFdxFIC/q2y75yW7Lds2r9/f5pbGbJtzjXHM9hqX7G79snGm71ggb/LrgZjaEwLBeHT0gN4FEydNLqh4m4pUQ6M1LWbpsXCvkSOH8lt5ehEJ4FwbUYv/k+qGGdNBKgB66uFoHKSZQNdUPCx4FVBPd2YZIO0DWkffDwjSZWGf/ZHvC7YFIyM4OnZ0H5DrAQX2Nzz7G9adaADkzkCJEQgaIE/8yIbgvOCAP6EDABJQzQyOGyPsQDMGMIhhjKSA2SRw8ROnDS5BCogxmgH0/k1+E5HPSBLMxo+LTgF9CRFglsgH8YMfbxuzOnUEQKrWG7SbnveoFCouhTeLPO/VZs97swWU63Ao+DU/tAm6PwFl0VdbyUaoORf2H/tqm70SDiyARlfCs6KzAFAA2bLg4U6oPgnqnoYqU8TdvvjZegnG5mHoCVi9BspsqDn1N3tX+vZuf4z5dL93knFys+SXUE8AAAAJcEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQfoBw8PKgC4t3QcAAAAGXRFWHRDb21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAAAAlQTFRFAAAA/////wAAzV63nAAAAIBJREFUeNqF0QEKAyEQQ1H99z90KYb9aBAFbCe8MMKOdRgeMhmU4WJgS8p4Xw296mmcJS7rTi+f6+Q3gfF3Jv8rxWmCBFb+N0HIYywHRfMhSOV4kyidoKOG64LskYRxR/jARhxvKtQf23+wh5zGSLOPkjLOEsM242lgFKI7L8Nufv6zAR1Q0qgmAAAAAElFTkSuQmCC" width="480" height="480">
</body>
</html>

Platform:
Reproduced on Fedora 40 x86_64; almost certainly platform-agnostic

Activity

  1. added
    C-untriaged
    on Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions