Skip to content

Commit 8577aa2

Browse files
committed
[css-contain-3] Define inline-size containment #1031
1 parent d554225 commit 8577aa2

File tree

1 file changed

+88
-37
lines changed

1 file changed

+88
-37
lines changed

css-contain-3/Overview.bs

+88-37
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Strong Containment: the 'contain' property</h2>
7878

7979
<pre class='propdef partial'>
8080
Name: contain
81-
New Values: layout || style || paint || [ size | inline-size | block-size ]
81+
New Values: layout || style || paint || [ size | inline-size ]
8282
</pre>
8383

8484
<dl dfn-type=value dfn-for=contain>
@@ -87,11 +87,6 @@ Strong Containment: the 'contain' property</h2>
8787
The value turns on <a>inline-size containment</a> for the element.
8888
This ensures that the inline [=size containment box|containment box=] can be laid out
8989
without needing to examine its descendants.
90-
<dt><dfn>block-size</dfn>
91-
<dd>
92-
The value turns on <a>block-size containment</a> for the element.
93-
This ensures that the block [=size containment box|containment box=] can be laid out
94-
without needing to examine its descendants.
9590
</dl>
9691

9792

@@ -104,21 +99,85 @@ Types of Containment</h2>
10499
Inline-Size Containment</h3>
105100

106101
Giving an element <dfn export>inline-size containment</dfn>
107-
makes its [=principal box=] behave as a [=size containment box=]
108-
on the [=inline axis=].
109-
110-
Issue(1031): Define inline-size containment in more detail
102+
applies [=size containment=] on the element’s [=inline axis=].
103+
That means the [=intrinsic size=] of the [=size containment box=]
104+
on the element’s [=inline axis=]
105+
is determined as if the element had no content.
106+
However, content continues to impact the element’s [=block axis=] [=intrinsic size=].
107+
108+
In some cases,
109+
changes in the [=block size=] can impact layout in the parent formatting context,
110+
which then impacts the [=inline axis|inline=] [=available space=]
111+
(e.g. by triggering scrollbars on an ancestor element)
112+
or the result of [=container size queries=],
113+
which then impacts the element’s [=inline size=],
114+
creating a dependency of this [=inline size=] on the element’s content.
115+
To prevent infinite cycles,
116+
if this then results in a different [=block size=] on the element,
117+
that new [=block size=] can impact the parent formatting context,
118+
but not in a way that reverts it to the previously-problematic layout.
119+
For example, if scrollbars were introduced, they are not then removed;
120+
or if the inline size was reduced, it is not then restored to its previous size.
121+
122+
Note: This is similar to the logic governing float placement,
123+
in which a float whose logical height cannot fit
124+
is shifted down to find more space,
125+
which might also give it more inline-axis available space
126+
and thus produce a shorter float
127+
whose height could have fit in the initial space,
128+
but it is not moved back up
129+
(where it would again be narrower, and thus taller, and thus not fit).
111130

131+
<div class=example>
132+
For example,
133+
the following <code>article</code> is constrained by both
134+
the overall <code>section</code> ''width'',
135+
and impacted by the floated <code>div</code>s.
112136

113-
<h3 id='containment-block-size'>
114-
Block-Size Containment</h3>
115-
116-
Giving an element <dfn export>block-size containment</dfn>
117-
makes its [=principal box=] behave as a [=size containment box=]
118-
on the [=block axis=].
137+
<pre class=lang-css>
138+
&lt;section style="width: 200px; border: solid; display: flow-root;">
139+
&lt;!-- floated elements that impact the available space -->
140+
&lt;div style="float: left; width: 50px; height: 80px; background: red;">&lt;/div>
141+
&lt;div style="float: right; width: 50px; height: 80px; background: red;">&lt;/div>
142+
&lt;div style="float: left; width: 160px; height: 80px; background: red;">&lt;/div>
143+
144+
&lt;!-- parent layout, determining context -->
145+
&lt;article style="border: solid; display: flow-root; min-width: min-content;">
146+
&lt;header style="background: orange; aspect-ratio: 1/1;">
147+
&lt;h4 style="margin:0;">Article Title&lt;/h4>
148+
&lt;/header>
149+
&lt;/article>
150+
&lt;/section>
151+
</pre>
119152

120-
Issue(1031): Define block-size containment in more detail
153+
The block layout algorithm will attempt to layout the <code>article</code>
154+
in the first available space between the first two floated <code>div</code>s.
155+
However, the <code>header</code> ''aspect-ratio''
156+
requires a space with ''height'' equal or greater to the ''width'',
157+
and the available space is 100px wide by 80px tall,
158+
so the <code>article</code> is unable to fit.
159+
As a result, the block layout algorithm moves on,
160+
and attempts to layout the <code>article</code> in the next available space.
161+
162+
Since <code>article</code> ''min-width'' depends on the ''min-ccontent'' size,
163+
it will likley be too large to fit in the 40px wide space
164+
beside the final floated <code>div</code>,
165+
and continue to layout below that <code>div</code> as well--
166+
forming a 200px square below all the floated elements.
167+
168+
However, if the ''min-width'' is removed from the <code>article</code>,
169+
or if [=inline-size containment=] is added to
170+
either the <code>article</code> or <code>header</code>,
171+
then the <code>article</code> will fit as a 40px square
172+
next to the final floated <code>div</code>.
173+
Even though this resulting size could also fit in the initial space,
174+
agents do not backtrack
175+
and attempt to place the <code>article</code>
176+
in a context that previously failed.
177+
</div>
121178

179+
Issue(1031): Define inline-size containment in more detail
180+
(including additional examples)
122181

123182
<h2 id="container-queries">
124183
Container Queries</h2>
@@ -190,31 +249,23 @@ Creating Query Containers: the 'container-type' property</h3>
190249
<dl dfn-type=value dfn-for=container-type>
191250
<dt><dfn>size</dfn>
192251
<dd>
193-
Establishes a [=query container=] for [=size queries=]
252+
Establishes a [=query container=] for [=container size queries=]
194253
on both the [=inline axis|inline=] and [=block axis=].
195254
Applies [=layout containment=],
196255
[=style containment=],
197256
and [=size containment=]
198257
to the [=principal box=].
199258
<dt><dfn>inline-size</dfn>
200259
<dd>
201-
Establishes a [=query container=] for [=size queries=]
260+
Establishes a [=query container=] for [=container size queries=]
202261
on the container’s own [=inline axis=].
203262
Applies [=layout containment=],
204263
[=style containment=],
205264
and [=inline-size containment=]
206265
to the [=principal box=].
207-
<dt><dfn>block-size</dfn>
208-
<dd>
209-
Establishes a [=query container=] for [=size queries=]
210-
on the container’s own [=block axis=].
211-
Applies [=layout containment=],
212-
[=style containment=],
213-
and [=block-size containment=]
214-
to the [=principal box=].
215266
<dt><dfn>style</dfn>
216267
<dd>
217-
Establishes a [=query container=] for [=style queries=].
268+
Establishes a [=query container=] for [=container style queries=].
218269
<dt><dfn>state</dfn>
219270
<dd>
220271
Establishes a [=query container=] for [=state queries=].
@@ -374,7 +425,7 @@ Container Queries: the ''@container'' rule</h3>
374425
The <dfn at-rule id="at-ruledef-container">@container</dfn> rule
375426
is a [=conditional group rule=] whose condition is
376427
a <dfn export>container query</dfn>,
377-
which is a boolean combination of [=size queries=] and/or [=style queries=].
428+
which is a boolean combination of [=container size queries=] and/or [=container style queries=].
378429
Style declarations within the <<stylesheet>> block of an ''@container'' rule
379430
are [[css-cascade-4#filtering|filtered]] by its condition
380431
to only match when the [=container query=]
@@ -432,7 +483,7 @@ Container Queries: the ''@container'' rule</h3>
432483
is a match for both ''container-type/inline-size'' and ''container-type/block-size''.
433484

434485
Once an eligible [=query container=] has been selected for an element,
435-
each [=container feature=] in the <<container-query-list>>
486+
each [=container feature=] in the <<container-condition>>
436487
is evaluated against that [=query container=].
437488
If the selected [=query container=]
438489
is not a valid 'container-type' for the feature,
@@ -451,14 +502,14 @@ Container Queries: the ''@container'' rule</h3>
451502

452503
The styles above will only be applied
453504
if there nearest ancestor container named "card"
454-
meets both the '@container/inline-size' and [=style queries|style=] conditions.
505+
meets both the '@container/inline-size' and [=container style query|style=] conditions.
455506
</div>
456507

457508
Style rules defined on an element inside multiple nested [=container queries=]
458509
apply when all of the wrapping [=container queries=] are true for that element.
459510

460511
Note: Nested [=container queries=] can evaluate in relation to different containers,
461-
so it is not always possible to merge the individual <<container-query-list>>s
512+
so it is not always possible to merge the individual <<container-condition>>s
462513
into a single query.
463514

464515
<h3 id="animated-containers">
@@ -534,7 +585,7 @@ Container Features</h2>
534585
<h3 id="size-container">
535586
Size Container Features</h3>
536587

537-
A <dfn export>size query</dfn>
588+
A <dfn export>container size query</dfn>
538589
(syntactically represented as <<size-query>>)
539590
allows querying
540591
the size of the [=query container=]’s [=principal box=].
@@ -550,7 +601,7 @@ Size Container Features</h3>
550601

551602
If the [=query container=] does not have a [=principal box=],
552603
or the principal box is not a [=layout containment box=],
553-
or the [=query container=] does not support [=size queries=] on the relevant axes,
604+
or the [=query container=] does not support [=container size queries=] on the relevant axes,
554605
then the result of evaluating the [=size feature=] is unknown.
555606

556607
[=Relative length=] units in [=container query=] conditions
@@ -685,7 +736,7 @@ Orientation: the '@container/orientation' feature</h4>
685736
<h3 id="style-container">
686737
Style Container Features</h3>
687738

688-
A <dfn export>style queries</dfn>
739+
A <dfn export>container style query</dfn>
689740
(syntactically represented by <<style-query>>)
690741
allows querying
691742
the [=computed values=] of the [=query container=].
@@ -749,11 +800,11 @@ Container Relative Lengths: the ''cqw'', ''cqh'', ''cqi'', ''cqb'', ''cqmin'', '
749800

750801
For each element,
751802
[=container query length=] units are evaluated
752-
as [=size queries=] on the relevant axis (or axes)
803+
as [=container size queries=] on the relevant axis (or axes)
753804
described by the unit.
754805
The [=query container=] for each axis
755806
is the nearest ancestor container
756-
that accepts [=size queries=] on that axis.
807+
that accepts [=container size queries=] on that axis.
757808
If no eligible [=query container=] is available,
758809
then use the [=small viewport size=] for that axis.
759810

0 commit comments

Comments
 (0)