Skip to content

Commit 32ebbe8

Browse files
committed
[css-contain-2] Clarify how sizing containment works
This is not meant to change the expected behavior, however the original text was not very clearly phrased, hence this rewrite.
1 parent 7523501 commit 32ebbe8

File tree

1 file changed

+120
-75
lines changed

1 file changed

+120
-75
lines changed

css-contain-2/Overview.bs

Lines changed: 120 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ spec:css-sizing-4; type:property; text:contain-intrinsic-size
4646
spec:css-sizing-4; type:property; text:aspect-ratio
4747
spec:intersection-observer; type:dfn; text:intersection root
4848
spec:css-sizing-3; type:value; for:height; text:auto
49+
spec:css-sizing-3; type:property; text:width
50+
spec:css-sizing-3; type:property; text:height
51+
spec:css-sizing-3; type:value; for:width; text:min-content
52+
spec:css-sizing-3; type:value; for:width; text:max-content
4953
</pre>
5054

5155
<h2 id='intro'>
@@ -476,50 +480,97 @@ Size Containment</h3>
476480
contain-size-056.html
477481
</wpt>
478482

479-
1. When calculating the size of the [=size containment box=],
480-
including when computing its [=intrinsic size=],
481-
it must be treated as having no contents.
483+
1. Laying out a [=size containment box=] and its content is conceptually done in two phases:
484+
<dl>
485+
<dt><dfn>Sizing as if empty</dfn>
486+
<dd>
487+
The [=used value|used=] 'width' and 'height' of the [=size containment box|containment box=]
488+
are determined as if performing a normal layout of the box,
489+
except that it is treated as having no content--
490+
not even through pseudo elements such as ''::before'', ''::after'', or ''::marker''.
482491

483-
<wpt>
484-
contain-size-021.html
485-
contain-size-023.html
486-
contain-size-025.html
487-
contain-size-027.html
488-
contain-size-061.html
489-
contain-size-062.html
490-
contain-size-063.html
491-
contain-size-borders.html
492-
contain-size-fieldset-001.html
493-
contain-size-fieldset-002.html
494-
contain-size-select-001.html
495-
contain-size-select-002.html
496-
contain-size-scrollbars-001.html
497-
contain-size-scrollbars-002.html
498-
contain-size-scrollbars-003.html
499-
contain-size-scrollbars-004.html
500-
501-
contain-size-button-001.html
502-
contain-size-flexbox-001.html
503-
contain-size-flexbox-002.html
504-
contain-size-grid-001.html
505-
</wpt>
492+
<wpt>
493+
contain-size-021.html
494+
contain-size-023.html
495+
contain-size-025.html
496+
contain-size-027.html
497+
contain-size-061.html
498+
contain-size-062.html
499+
contain-size-063.html
500+
contain-size-borders.html
501+
contain-size-fieldset-001.html
502+
contain-size-fieldset-002.html
503+
contain-size-select-001.html
504+
contain-size-select-002.html
505+
contain-size-scrollbars-001.html
506+
contain-size-scrollbars-002.html
507+
contain-size-scrollbars-003.html
508+
contain-size-scrollbars-004.html
506509

507-
Note: Even when the element's [=sizing properties=] are ''height/auto''
508-
this does not necessarily make the element zero-sized:
509-
properties set on the element itself,
510-
such as the 'columns' property or the 'grid' property,
511-
continue to be taken into account.
510+
contain-size-button-001.html
511+
contain-size-flexbox-001.html
512+
contain-size-flexbox-002.html
513+
contain-size-grid-001.html
514+
</wpt>
512515

513-
<wpt>
514-
contain-size-grid-002.html
515-
contain-size-grid-003.html
516-
contain-size-multicol-001.html
517-
contain-size-multicol-as-flex-item.html
518-
</wpt>
516+
<a>Replaced elements</a> must be treated as having an intrinsic width and height of 0.
517+
518+
<wpt>
519+
contain-size-013.html
520+
contain-size-041.html
521+
contain-size-042.html
522+
contain-size-replaced-001.html
523+
contain-size-replaced-002.html
524+
contain-size-replaced-003a.html
525+
contain-size-replaced-003b.html
526+
contain-size-replaced-003c.html
527+
contain-size-replaced-004.html
528+
contain-size-replaced-005.html
529+
</wpt>
530+
531+
[=Size containment boxes=] must be treated
532+
as if they had no [=intrinsic aspect ratio=].
533+
534+
Note: Size containment only suppresses the [=intrinsic aspect ratio=],
535+
not [=preferred aspect ratio=],
536+
so properties like 'aspect-ratio' which affect that [=preferred aspect ratio=] directly
537+
are honored.
538+
539+
<wpt pathprefix=css/css-sizing/aspect-ratio/>
540+
replaced-element-023.html
541+
replaced-element-025.html
542+
replaced-element-027.html
543+
</wpt>
544+
545+
All CSS properties of the [=size containment box=] are taken into account
546+
as they would be when performing layout norally.
547+
<!-- uncomment this (and edit the following note) if we want to allow grid to opt into not doing track sizing etc:
548+
Other specifications may make specific explicit exemptions.
549+
-->
519550

520-
Then,
521-
its contents must then be laid out into the [=size containment box=]'s resolved size normally (including any pseudo-elements),
522-
i.e. [=size containment=] has no effect in this phase.
551+
<wpt>
552+
contain-size-replaced-006.html
553+
</wpt>
554+
555+
Note: Even when the element's [=sizing properties=] are ''height/auto''
556+
this does not necessarily make the element zero-sized:
557+
properties set on the element itself,
558+
such as the 'columns' property or the 'grid' property,
559+
continue to be taken into account.
560+
561+
<wpt>
562+
contain-size-grid-002.html
563+
contain-size-grid-003.html
564+
contain-size-multicol-001.html
565+
contain-size-multicol-as-flex-item.html
566+
</wpt>
567+
568+
<dt><dfn>Laying out in-place</dfn>
569+
<dd>
570+
The [=size containment box|containment box=]'s content
571+
(including any pseudo-element)
572+
must then be laid out into the now fixed-size [=size containment box|containment box=] normally.
573+
</dl>
523574

524575
Note: [=size containment=] does not suppress baseline alignment.
525576
See [=layout containment=] for that.
@@ -528,7 +579,15 @@ Size Containment</h3>
528579
contain-size-baseline-001.html
529580
</wpt>
530581

531-
<a>Replaced elements</a> must be treated as having an intrinsic width and height of 0.
582+
2.
583+
The [=intrinsic sizes=] of the [=size containment box=]
584+
are determined as if the element had no content,
585+
following the same logic as when [=sizing as if empty=].
586+
587+
Note: This affects explit invocations of the ''min-content'' or ''max-content'' keywords,
588+
as well as any calculation that depends on these measurement,
589+
such as sizing <span class=informative>[=grid tracks=]</span> into which a size contained item is placed,
590+
or if [=fit-content sizing=] the contaiing box's parent.
532591

533592
<wpt>
534593
contain-size-013.html
@@ -544,46 +603,32 @@ Size Containment</h3>
544603
contain-size-replaced-006.html
545604
</wpt>
546605

547-
2. [=Size containment boxes=] must be treated
548-
as if they had no [=intrinsic aspect ratio=].
549-
550-
Note: Size containment only suppresses the [=intrinsic aspect ratio=],
551-
not [=preferred aspect ratio=],
552-
so properties like 'aspect-ratio' which affect that [=preferred aspect ratio=] directly
553-
are honored.
554-
555-
<wpt pathprefix=css/css-sizing/aspect-ratio/>
556-
replaced-element-023.html
557-
replaced-element-025.html
558-
replaced-element-027.html
559-
</wpt>
560-
561-
<div class=example>
562-
Given the following markup and style, the image would be sized to 100px by 100px,
563-
as the aspect ratio set by the 'aspect-ratio' property takes effect.
564-
<pre><code class=lang-css>
565-
img {
566-
width: 100px;
567-
aspect-ratio: 1/1;
568-
contain: size;
569-
}
570-
</code><code class=lang-html>
571-
&lt;img src="https://www.example.com/300x100.jpg">
572-
</code></pre>
573-
574-
If the 'aspect-ratio' property had not been declared,
575-
the image would have been 100px by 0px,
576-
as its intrinsic aspect ratio is suppressed,
577-
and its intrinsic height is treated as 0.
578-
</div>
579-
580606
3. [=Size containment boxes=] are <a spec=css-break-3>monolithic</a> (See [[CSS-BREAK-3#possible-breaks]]).
581607

582608
<wpt>
583609
contain-size-breaks-001.html
584610
contain-size-monolithic-001.html
585611
</wpt>
586612

613+
<div class=example>
614+
Given the following markup and style, the image would be sized to 100px by 100px,
615+
as the aspect ratio set by the 'aspect-ratio' property takes effect.
616+
<pre><code class=lang-css>
617+
img {
618+
width: 100px;
619+
aspect-ratio: 1/1;
620+
contain: size;
621+
}
622+
</code><code class=lang-html>
623+
&lt;img src="https://www.example.com/300x100.jpg">
624+
</code></pre>
625+
626+
If the 'aspect-ratio' property had not been declared,
627+
the image would have been 100px by 0px,
628+
as its intrinsic aspect ratio is suppressed,
629+
and its intrinsic height is treated as 0.
630+
</div>
631+
587632
By itself, <a>size containment</a> does not offer much optimization opportunity.
588633
Its primary benefit on its own is that tools which want to lay out the [=size containment box|containment box=]'s contents
589634
based on the [=size containment box|containment box=]'s size
@@ -604,7 +649,7 @@ Size Containment</h3>
604649

605650
2. When laying out the page,
606651
if the [=size containment box|containment box=] is off-screen or obscured,
607-
the layout of its contents can be delayed or done at a lower priority.
652+
the layout of its contents (i.e. "[=laying out in-place=]") can be delayed or done at a lower priority.
608653

609654
<h3 id='containment-layout'>
610655
Layout Containment</h3>

0 commit comments

Comments
 (0)