Skip to content

Commit 9f03cf3

Browse files
committed
[css-sizing-4] Add intrinsic sizing example for aspect-ratio. w3c#4639
1 parent 73bd5ba commit 9f03cf3

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

css-sizing-4/Overview.bs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,37 @@ Intrinsic Aspect Ratios: the 'aspect-ratio' property</h3>
275275
</pre>
276276
</div>
277277

278+
<div class="example">
279+
In the following example:
280+
281+
<pre>
282+
&lt;div id=container style="height: 100px; float: left;">
283+
&lt;div id=item style="height: 100%; aspect-ratio: 1/1;">content&lt;/div>
284+
&lt;/div>
285+
</pre>
286+
287+
Since the height of the <code>#item</code> is a percentage that resolves against a definite container,
288+
the width of the item resolves to 100px for both its intrinsic size contributions as well as for final layout,
289+
so the container also sizes to a width of 100px.
290+
291+
<pre>
292+
&lt;div id=container style="height: auto; float: left;">
293+
&lt;div id=item style="height: 100%; aspect-ratio: 1/1;">content&lt;/div>
294+
&lt;/div>
295+
</pre>
296+
297+
In this next example,
298+
the percentage height of the item cannot be resolved and [=behaves as auto=]
299+
(see [[CSS2/visudet#the-height-property]]).
300+
Since both axes now have an [=automatic size=],
301+
the height becomes the [=ratio-dependent axis=].
302+
Calculating the [=intrinsic size contributions=] of the box
303+
produces a width derived from its content,
304+
and a height calculated from that width and the aspect ratio,
305+
yielding a square box (and a container) sized
306+
to the width of the word “content”.
307+
</div>
308+
278309
On non-replaced elements with an ''width/auto'' <a>inline size</a>
279310
(or any replaced element whose intrinsic <a>block size</a>
280311
depends on its <a>inline size</a>),

0 commit comments

Comments
 (0)