Skip to content

Commit 43db5f6

Browse files
committed
[css-images-4] Make scale-down a flag for cover/contain
Resolves w3c#1578
1 parent 480afc2 commit 43db5f6

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

css-images-4/Overview.bs

+105-1
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,111 @@ Gradient Color-Stops</h3>
14381438
Sizing Images and Objects in CSS {#sizing}
14391439
==========================================
14401440

1441-
Note: No change from [[css3-images]].
1441+
<!--
1442+
███████ ████████ ██ ████████ ██████ ████████ ████████ ████ ████████
1443+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
1444+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
1445+
██ ██ ████████ ██ ██████ ██ ██ ███████ ██████ ██ ██
1446+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
1447+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
1448+
███████ ████████ ██████ ████████ ██████ ██ ██ ████ ██
1449+
-->
1450+
1451+
Sizing Objects: the 'object-fit' property {#the-object-fit}
1452+
-----------------------------------------------------------
1453+
1454+
<pre class='propdef'>
1455+
Name: object-fit
1456+
Value: fill | none | [contain | cover] || scale-down
1457+
Initial: fill
1458+
Applies to: replaced elements
1459+
Inherited: no
1460+
Percentages: n/a
1461+
Media: visual
1462+
Computed value: specified value
1463+
Animatable: no
1464+
</pre>
1465+
1466+
The 'object-fit' property specifies how the contents of a replaced element
1467+
should be fitted to the box established by its used height and width.
1468+
1469+
<dl dfn-type=value dfn-for=object-fit>
1470+
<dt><dfn>fill</dfn>
1471+
<dd>
1472+
The replaced content is sized to fill the element's content box:
1473+
the object's <a>concrete object size</a> is the element's used width and height.
1474+
1475+
<dt><dfn>none</dfn>
1476+
<dd>
1477+
The replaced content is not resized to fit inside the element's content box:
1478+
determine the object's <a>concrete object size</a>
1479+
using the <a>default sizing algorithm</a> with no specified size,
1480+
and a <a>default object size</a> equal to the replaced element's used width and height.
1481+
1482+
<dt><dfn>contain</dfn>
1483+
<dd>
1484+
The replaced content is sized to maintain its aspect ratio
1485+
while fitting within the element's content box:
1486+
its <a>concrete object size</a> is resolved as a <a>contain constraint</a>
1487+
against the element's used width and height.
1488+
1489+
If the ''scale-down'' flag is used, size the content as if ''object-fit/none'' or ''object-fit/contain'' were specified,
1490+
whichever would result in a smaller <a>concrete object size</a>.
1491+
1492+
Note: Both ''object-fit/none'' and ''object-fit/contain'' respect the content's intrinsic aspect ratio,
1493+
so the concept of "smaller" is well-defined.
1494+
1495+
<dt><dfn>cover</dfn>
1496+
<dd>
1497+
The replaced content is sized to maintain its aspect ratio
1498+
while filling the element's entire content box:
1499+
its <a>concrete object size</a> is resolved as a <a>cover constraint</a>
1500+
against the element's used width and height.
1501+
1502+
If the ''scale-down'' flag is used, size the content as if ''object-fit/none'' or ''object-fit/cover'' were specified,
1503+
whichever would result in a smaller <a>concrete object size</a>.
1504+
1505+
Note: Both ''object-fit/none'' and ''object-fit/cover'' respect the content's intrinsic aspect ratio,
1506+
so the concept of "smaller" is well-defined.
1507+
1508+
<dt><dfn>scale-down</dfn>
1509+
<dd>
1510+
Equivalent to ''contain scale-down''.
1511+
</dl>
1512+
1513+
If the content does not completely fill the replaced element's content box,
1514+
the unfilled space shows the replaced element's background.
1515+
Since replaced elements always clip their contents to the content box,
1516+
the content will never overflow.
1517+
See the 'object-position' property for positioning the object with respect to the content box.
1518+
1519+
<figure>
1520+
<img src="images/img_scale.png" style="border: thin solid black;" alt="">
1521+
1522+
<figcaption>
1523+
An example showing how four of the values of 'object-fit' cause the replaced element (blue figure)
1524+
to be scaled to fit its height/width box (shown with a green background),
1525+
using the initial value for 'object-position'.
1526+
In this case, ''scale-down'' and ''scale-down contain'' would look identical to ''object-fit/contain'',
1527+
and ''scale-down cover'' would look identical to ''object-fit/none''.
1528+
</figcaption>
1529+
</figure>
1530+
1531+
Note: The 'object-fit' property has similar semantics to
1532+
the <code>fit</code> attribute in [[SMIL10]]
1533+
and the <<meetOrSlice>> parameter
1534+
on the <a href="https://www.w3.org/TR/SVG11/coords.html#PreserveAspectRatioAttribute"><code>preserveAspectRatio</code> attribute</a> in [[SVG11]].
1535+
1536+
Note: Per the <a>object size negotiation</a> algorithm,
1537+
the <a>concrete object size</a>
1538+
(or, in this case, the size of the content)
1539+
does not directly scale the object itself -
1540+
it is merely passed to the object as information about the size of the visible canvas.
1541+
How to then draw into that size is up to the image format.
1542+
In particular, raster images always scale to the given size,
1543+
while SVG uses the given size as the size of the "SVG Viewport"
1544+
(a term defined by SVG)
1545+
and then uses the values of several attributes on the root <code>&lt;svg></code> element to determine how to draw itself.
14421546

14431547
Image Processing {#image-processing}
14441548
====================================

0 commit comments

Comments
 (0)