Skip to content

Commit 512bd7e

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 512bd7e

File tree

1 file changed

+124
-81
lines changed

1 file changed

+124
-81
lines changed

css-contain-2/Overview.bs

Lines changed: 124 additions & 81 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,59 +480,15 @@ 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.
484+
The [=intrinsic sizes=] of the [=size containment box=]
485+
are determined as if the element had no content,
486+
following the same logic as when [=sizing as if empty=].
482487

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>
506-
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.
512-
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>
519-
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.
523-
524-
Note: [=size containment=] does not suppress baseline alignment.
525-
See [=layout containment=] for that.
526-
527-
<wpt>
528-
contain-size-baseline-001.html
529-
</wpt>
530-
531-
<a>Replaced elements</a> must be treated as having an intrinsic width and height of 0.
488+
Note: This affects explicit invocations of the ''min-content'' or ''max-content'' keywords,
489+
as well as any calculation that depends on these measurement,
490+
such as sizing <span class=informative>[=grid tracks=]</span> into which a size contained item is placed,
491+
or if [=fit-content sizing=] the containment box's parent.
532492

533493
<wpt>
534494
contain-size-013.html
@@ -544,38 +504,102 @@ Size Containment</h3>
544504
contain-size-replaced-006.html
545505
</wpt>
546506

547-
2. [=Size containment boxes=] must be treated
548-
as if they had no [=intrinsic aspect ratio=].
507+
2. Laying out a [=size containment box=] and its content is conceptually done in two phases:
508+
<dl>
509+
<dt><dfn>Sizing as if empty</dfn>
510+
<dd>
511+
The [=used value|used=] 'width' and 'height' of the [=size containment box|containment box=]
512+
are determined as if performing a normal layout of the box,
513+
except that it is treated as having no content--
514+
not even through pseudo elements such as ''::before'', ''::after'', or ''::marker''.
549515

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.
516+
<wpt>
517+
contain-size-021.html
518+
contain-size-023.html
519+
contain-size-025.html
520+
contain-size-027.html
521+
contain-size-061.html
522+
contain-size-062.html
523+
contain-size-063.html
524+
contain-size-borders.html
525+
contain-size-fieldset-001.html
526+
contain-size-fieldset-002.html
527+
contain-size-select-001.html
528+
contain-size-select-002.html
529+
contain-size-scrollbars-001.html
530+
contain-size-scrollbars-002.html
531+
contain-size-scrollbars-003.html
532+
contain-size-scrollbars-004.html
554533

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>
534+
contain-size-button-001.html
535+
contain-size-flexbox-001.html
536+
contain-size-flexbox-002.html
537+
contain-size-grid-001.html
538+
</wpt>
560539

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>
540+
<a>Replaced elements</a> must be treated as having an intrinsic width and height of 0
541+
and no [=intrinsic aspect ratio=].
573542

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>
543+
Note: Size containment only suppresses the [=intrinsic aspect ratio=],
544+
so properties like 'aspect-ratio' which affect that [=preferred aspect ratio=] directly
545+
are honored.
546+
547+
548+
<wpt>
549+
contain-size-013.html
550+
contain-size-041.html
551+
contain-size-042.html
552+
contain-size-replaced-001.html
553+
contain-size-replaced-002.html
554+
contain-size-replaced-003a.html
555+
contain-size-replaced-003b.html
556+
contain-size-replaced-003c.html
557+
contain-size-replaced-004.html
558+
contain-size-replaced-005.html
559+
</wpt>
560+
561+
<wpt pathprefix=css/css-sizing/aspect-ratio/>
562+
replaced-element-023.html
563+
replaced-element-025.html
564+
replaced-element-027.html
565+
</wpt>
566+
567+
All CSS properties of the [=size containment box=] are taken into account
568+
as they would be when performing layout normally.
569+
<!-- uncomment this (and edit the following note) if we want to allow grid to opt into not doing track sizing etc:
570+
Other specifications may make specific explicit exemptions.
571+
-->
572+
573+
<wpt>
574+
contain-size-replaced-006.html
575+
</wpt>
576+
577+
Note: Even when the element's [=sizing properties=] specify an intrinsic size,
578+
this does not necessarily make the element zero-sized:
579+
properties set on the element itself,
580+
such as the 'columns' property or the 'grid' property,
581+
continue to be taken into account.
582+
583+
<wpt>
584+
contain-size-grid-002.html
585+
contain-size-grid-003.html
586+
contain-size-multicol-001.html
587+
contain-size-multicol-as-flex-item.html
588+
</wpt>
589+
590+
<dt><dfn>Laying out in-place</dfn>
591+
<dd>
592+
The [=size containment box|containment box=]'s content
593+
(including any pseudo-elements)
594+
must then be laid out into the now fixed-size [=size containment box|containment box=] normally.
595+
</dl>
596+
597+
Note: [=Size containment=] does not suppress baseline alignment.
598+
See [=layout containment=] for that.
599+
600+
<wpt>
601+
contain-size-baseline-001.html
602+
</wpt>
579603

580604
3. [=Size containment boxes=] are <a spec=css-break-3>monolithic</a> (See [[CSS-BREAK-3#possible-breaks]]).
581605

@@ -584,6 +608,25 @@ Size Containment</h3>
584608
contain-size-monolithic-001.html
585609
</wpt>
586610

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

605648
2. When laying out the page,
606649
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.
650+
the layout of its contents (i.e. "[=laying out in-place=]") can be delayed or done at a lower priority.
608651

609652
<h3 id='containment-layout'>
610653
Layout Containment</h3>

0 commit comments

Comments
 (0)