Bug 154049 - The heights of SVG elements using relative sizes are miscalculated within border-box parents
Summary: The heights of SVG elements using relative sizes are miscalculated within bor...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-02-09 14:59 PST by anthony.lalande@gmail.com
Modified: 2022-07-15 17:18 PDT (History)
7 users (show)

See Also:


Attachments
black-screen-shot (146.83 KB, image/png)
2016-02-10 13:09 PST, Said Abou-Hallawa
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description anthony.lalande@gmail.com 2016-02-09 14:59:34 PST
Overview:
When including an SVG element within a parent element that uses `box-sizing: border-box`, the relative height of the SVG element seems to be miscalculated.


Steps to reproduce:
- Create an enclosing block element with the `box-sizing: border-box` directive.
- Add a padding value > 0 for this enclosing element.
- Create an inner SVG element with the `height: 100%` directive.
- Observe that the SVG element has a height that is too short by a factor of 2x the parent's padding.



Expected results:

I would expect an SVG element to be sized identically to a `<div>` element that uses `box-sizing: border-box`, as here:
https://jsfiddle.net/p9ke6bo9/

Note that the underlying black box forms a 10px "border" all around the white box.


Actual results:

When you change the `<div>` element to `<svg>` in the example above, the black outline grows to 30px at the bottom:
https://jsfiddle.net/p9ke6bo9/1/

This seems to be because the `<svg>` element is subtracting 4 * 10px (instead of 2 * 10px) from the parent element's height.


Additional example:

When you remove the `box-sizing: border-box` directive from the outer element, the inner `<svg>` element draws correctly:
https://jsfiddle.net/p9ke6bo9/3/
Comment 1 Said Abou-Hallawa 2016-02-10 13:09:46 PST
Created attachment 271022 [details]
black-screen-shot

When opening https://jsfiddle.net/p9ke6bo9/1/, sometimes I get whole page filled with black. See the attached picture black-screen-shot.
Comment 2 Swimmer F 2019-12-12 19:44:52 PST
Ran into this bug today (I think).
> - Observe that the SVG element has a height that is too short by a factor of 2x the parent's padding.
My elements end up too tall.

https://jsfiddle.net/nj5a0dyq/

Playing with some paramters led me to the following findings:

- Behaves as expected as long as the sum of padding-top + padding-bottom is less than half the container's height
- Any padding, top or bottom, beyond half the container's height causes the <svg> to become that much taller instead of making it that much shorter (expected behaviour)
Comment 3 Radar WebKit Bug Importer 2022-07-15 17:18:55 PDT
<rdar://problem/97102170>