Closed Bug 1640560 Opened 6 years ago Closed 1 year ago

SVG with `height="100%"` scales differently from Chrome when inside an automatically-sized table cell in a fixed-height table

Categories

(Core :: SVG, defect)

76 Branch
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: mozilla, Unassigned)

Details

Attachments

(2 files)

Attached file svg-table.html —

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:76.0) Gecko/20100101 Firefox/76.0

Steps to reproduce:

Create an <svg width="100%" height="100%"> inside a fixed-sized table.

JSFiddle: https://jsfiddle.net/0b9cukLo/

Actual results:

In Mozilla the SVG scales to fill the allocated 400px of horizontal space, leaving the vertical dimension to stretch out the table.

Expected results:

In Chrome, Safari, IE 11, and Opera 12, the table is sized as requested at 400x200, and the SVG scales to fill that space (vertical space is the limiting factor).

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → SVG
Product: Firefox → Core

SVG 2 says that width="" and height="" attributes on an <svg> element are presentation attributes for the corresponding CSS properties:

https://svgwg.org/svg2-draft/geometry.html#Sizing

Since these are percentages, the <svg> has no intrinsic dimensions, but it does have an intrinsic aspect ratio inferred from the viewBox="":

https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS

CSS says that a percentage value for 'width' or 'height' resolves against the containing block size (the size of the table cell), unless the containing block's size depends on the the size of the box in question:

https://drafts.csswg.org/css-sizing-3/#sizing-values

The height of a table cell does depend on the size of its contents, despite the height="200" on the <table> itself. The <svg> is an inline, replaced element, so that means following the rules for percentage heights in inline layout (in CSS 2), which say that it computes to 'auto':

https://www.w3.org/TR/2011/REC-CSS2-20110607/visudet.html#the-height-property
https://drafts.csswg.org/css-sizing-3/#behave-auto

And finally an 'auto' height here when the element has a definite width and an intrinsic aspect ratio gets resolved accordingly:

https://drafts.csswg.org/css-images-3/#default-sizing

All of this is to say that I think Chrome's behavior is correct and ours is wrong.

Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true

Daniel, am I reading this right?

Flags: needinfo?(dholbert)

From my cursory look so far: I'm not sure. Note that tables are weird and are known to have interop issues & spec-completeness issues.

However, a few observations:

  • If I remove height="100%" from the SVG element, then Chrome changes their rendering to agree with Firefox.
  • And if I instead use style="height:auto" (still omitting the height attribute), Chrome still continues to agree with Firefox.
  • None of these changes impact Firefox's rendering.
    [EDIT: Initially I had said style="height:100%" caused Chrome to match Firefox as well, but this was a mistake on my part; I had a typo in my testing. Chrome does seem to treat height="100%" and style="height:100%" the same, roughly.]

I think Firefox's behavior might make more sense here (specifically, it makes sense that we're consistent), because:

  • As heycam noted above, the height attribute on an <svg> element is a presentation attribute (i.e. an alias) for the corresponding CSS property.
  • SVG2 says "The value "auto" for width and height on the ‘svg’ element is treated as 100%." (i.e. if no CSS/mapped-attribute 'height' is specified, then the default 'auto' value should behave as if we had specified height:100%)
  • Therefore: <svg height="100%"> (in the testcase) and <svg style="height:100%"> should behave the same as <svg style="height:auto"> and <svg>-with-no-height-specified. And these do all behave the same in Firefox (which I verified via tweaks to the provided testcase), but not in Chrome -- Chrome has this one different behavior specifically when the height attribute is used.

So there seems to be a Chrome bug/inconsistency here. I'm not sure which variant is correct offhand, but given that one of the branches of their inconsistency matches Firefox, it seems not-crazy to think that the Firefox/partial-Chrome consensus is likely reasonable.

Flags: needinfo?(dholbert)
Summary: SVG at 100% scales badly when inside a table cell → SVG with `height="100%"` scales differently from Chrome when inside a table cell

on the other hand: If I modify the testcase to specify an explicit height on the table cell (the td element), then we do change to match Chrome (and we start showing a similar inconsistency depending on whether the SVG element has height="100%" vs. height:auto). So our consistency that I was praising in comment 5 may be accidental rather than virtuous.

Anyway - answering the question from the needinfo: yeah, I think the reasoning in comment 3 makes sense, with the caveat that if Chrome were correct on this then I'd expect them to be consistent between the height="100%" and height-unspecified-or-auto scenarios (since auto is supposed to be equivalent to 100%). But anyway: that might just be a Chrome bug in the handling of auto rather than in the handling of 100%; or maybe there's a subtle reason it makes sense.

Summary: SVG with `height="100%"` scales differently from Chrome when inside a table cell → SVG with `height="100%"` scales differently from Chrome when inside an automatically-sized table cell in a fixed-height table

Chrome's behaviour has changed and now matches ours.

Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: