Skip to content

Commit 92b3517

Browse files
emiliozcorpan
authored andcommitted
Use width and height as intrinsic aspect ratio for img elements
For when the current request is not available or it doesn't have an intrinsic ratio (such as some SVG content). This specifies the proposal in WICG/intrinsicsize-attribute#16, which is implemented in both Firefox and Chromium behind a flag. Tests: https://github.com/web-platform-tests/wpt/blob/a57ec1432f22ac42e8e219a32e2abd7c0baa5b09/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio.tentative.html.
1 parent d107662 commit 92b3517

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

source

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3641,6 +3641,11 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
36413641
<li><dfn data-x-href="https://drafts.csswg.org/css-color/#transparent-black">transparent black</dfn></li>
36423642
</ul>
36433643

3644+
<p>The term <dfn
3645+
data-x-href="https://drafts.csswg.org/css-images/#intrinsic-aspect-ratio">intrinsic aspect
3646+
ratio</dfn> is used as defined in <cite>CSS Image Values and Replaced Content</cite> to define
3647+
the sizing of replaced content. <ref spec=CSSIMAGES></p>
3648+
36443649
<p>The term <dfn data-x-href="https://drafts.csswg.org/css-images-4/#paint-source">paint
36453650
source</dfn> is used as defined in <cite>CSS Image Values and Replaced Content</cite>
36463651
to define the interaction of certain HTML elements with the CSS 'element()'
@@ -115559,6 +115564,22 @@ input[type=image i][align=bottom i], object[align=bottom i] {
115559115564
property">map to the dimension properties</span> <span>'width'</span> and <span>'height'</span> on
115560115565
the element respectively.</p>
115561115566

115567+
<p>The <span>intrinsic aspect ratio</span> for an <code>img</code> element <var>img</var> is
115568+
computed as follows:</p>
115569+
115570+
<ol>
115571+
<li><p>If <var>img</var>'s <span>current request</span> is <span
115572+
data-x="img-available">available</span> and has an <span>intrinsic aspect ratio</span>, then
115573+
use that intrinsic aspect ratio.</p></li>
115574+
115575+
<li><p>If <var>img</var>'s <code data-x="attr-dim-width">width</code> and <code
115576+
data-x="attr-dim-height">height</code> attribute values, when parsed using the <span>rules for
115577+
parsing dimension values</span>, are both not an error, not a percentage, and non-zero, then use
115578+
the ratio resulting from dividing the <code data-x="attr-dim-width">width</code> attribute value
115579+
by the <code data-x="attr-dim-height">height</code> attribute value.</p></li>
115580+
115581+
<li><p>Otherwise, <var>img</var> has no <span>intrinsic aspect ratio</span>.</p></li>
115582+
</ol>
115562115583
</div>
115563115584

115564115585

0 commit comments

Comments
 (0)