Skip to content

Commit 211b2da

Browse files
committed
[css-contain-3] Begin sketching out container query work-in-progress
1 parent c280458 commit 211b2da

1 file changed

Lines changed: 231 additions & 0 deletions

File tree

css-contain-3/Overview.bs

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,242 @@ Strong Containment: the 'contain' property</h2>
8787

8888
Issue: [[css-contain-2#contain-property]]
8989

90+
<pre class='propdef'>
91+
Name: contain
92+
Value: none | strict | content | [ size || inline-size || layout || style || paint ]
93+
Initial: none
94+
Inherited: no
95+
Applies to: See <a href="#contain-applies">below</a>
96+
Computed value: the keyword ''contain/none'' or one or more of ''size'', ''inline-size'', ''layout'', ''style'', ''paint''
97+
Animation type: not animatable
98+
</pre>
99+
100+
<dl dfn-type=value dfn-for=contain>
101+
<dt><dfn>inline-size</dfn>
102+
<dd>
103+
The value turns on <a>inline-size containment</a> for the element.
104+
This ensures that the inline [=size containment box|containment box=] can be laid out
105+
without needing to examine its descendants.
106+
</dl>
107+
108+
<span id="contain-applies">This property generally applies to all elements (including [[css-pseudo-4#generated-content]])</span>,
109+
although some types of containment have no effect on some elements,
110+
as detailed in [[#containment-types]].
111+
In addition, in the case of [[SVG2]],
112+
the 'contain' property only applies to <{svg}> elements that have an associated CSS layout box.
113+
114+
90115
<h2 id='containment-types'>
91116
Types of Containment</h2>
92117

93118
Issue: [[css-contain-2#containment-types]]
94119

120+
<h3 id='containment-inline-size'>
121+
Inline-Size Containment</h3>
122+
123+
<dfn export>inline-size containment</dfn>
124+
125+
Issue: Define inline-size containment, maybe as a sub-section of size containment?
126+
Need feedback from implementors on what edge-cases need to be more clearly outlined here.
127+
128+
129+
<h2 id="container-query">
130+
Container Queries</h2>
131+
132+
While [=media queries=] provide a method to test aspects of the external user agent or device
133+
that a document is being displayed in (such as viewport dimensions or user preferences),
134+
<dfn export>container queries</dfn> allow testing aspects of elements inside the document
135+
(such as box dimensions or computed styles).
136+
137+
<h3 id="container-type">
138+
Creating Containers: the ''container-type'' property</h2>
139+
140+
<pre class='propdef'>
141+
Name: container-type
142+
Value: none | [ size || inline-size || block-size || style || state ]
143+
Initial: none
144+
Inherited: no
145+
Applies to: all elements
146+
Computed value: the keyword ''container-type/none'' or one or more of ''container-type/size'', ''container-type/inline-size'', ''container-type/style'', ''container-type/state''
147+
Animation type: not animatable
148+
</pre>
149+
150+
Issue: TODO: Bikeshed terms (consider "query" or "context"?)
151+
152+
<dl dfn-type=value dfn-for=container-type>
153+
<dt><dfn>size</dfn>
154+
<dd>
155+
Establishes a container for dimensional queries on both the inline and block axis.
156+
The user agent must change the [=used value=] of the 'contain' property
157+
so as to turn on [=layout containment=], [=style containment=], and [=size containment=].
158+
<dt><dfn>inline-size</dfn>
159+
<dd>
160+
Establishes a container for dimensional queries on the inline axis.
161+
The user agent must change the [=used value=] of the 'contain' property
162+
so as to turn on [=layout containment=], [=style containment=], and [=inline-size containment=].
163+
<dt><dfn>block-size</dfn>
164+
<dd>
165+
Establishes a container for dimensional queries on the block axis.
166+
The user agent must change the [=used value=] of the 'contain' property
167+
so as to turn on [=layout containment=], [=style containment=], and [=block-size containment=].
168+
<dt><dfn>style</dfn>
169+
<dd>
170+
Establishes a container for style queries.
171+
<dt><dfn>state</dfn>
172+
<dd>
173+
Establishes a container for state queries.
174+
</dl>
175+
176+
<div class=example>
177+
Many layouts rely on external sizing for the inline axis,
178+
while allowing the block axis to auto-size based on content.
179+
Establishing an ''container/inline-size'' container makes that behavior explicit,
180+
so that the inline-dimension can be queried,
181+
without impacting normal layout of the block dimensions:
182+
183+
<pre class=lang-css>
184+
section {
185+
container: inline-size;
186+
}
187+
188+
h2 { font-size: 1.2em; }
189+
190+
@container (width > 40em) {
191+
h2 { font-size: 1.5em; }
192+
}
193+
</pre>
194+
195+
The ''em'' value is relative to the <a>computed value</a> of 'font-size'
196+
on the ''section'' container.
197+
</div>
198+
199+
<div class=example>
200+
Containers can also expose computed style values for querying.
201+
This can be useful for toggling behavior across multiple properties:
202+
203+
<pre class=lang-css>
204+
section {
205+
container: style;
206+
}
207+
208+
@container (--cards == true) {
209+
article {
210+
border: thin solid silver;
211+
border-radius: 0.5em;
212+
padding: 1em;
213+
}
214+
}
215+
</pre>
216+
</div>
217+
218+
219+
<h3 id="container-name">
220+
Naming Containers: the ''container-name'' property</h2>
221+
222+
<pre class='propdef'>
223+
Name: container-name
224+
Value: none | [ <<custom-ident>> | <<string>> ]+
225+
Initial: none
226+
Inherited: no
227+
Applies to: all elements
228+
Computed value: the keyword ''container/none'' or a list of custom identifiers
229+
Animation type: not animatable
230+
</pre>
231+
232+
Issue: TODO: Bikeshed terms (consider "query" or "context"?)
233+
234+
<div class=example>
235+
In some cases, we want to query aspects of a specific container,
236+
even if it's not the nearest ancestor container.
237+
For example, we might want to query the height of a main content area,
238+
and the width of a more nested inline-container.
239+
240+
<pre class=lang-css>
241+
main {
242+
container-type: size;
243+
container-name: layout;
244+
}
245+
246+
.grid-item {
247+
container-type: inline-size;
248+
container-name: component;
249+
}
250+
251+
@container layout (block-size > 12em) {
252+
.card { margin-block: 2em; }
253+
}
254+
255+
@container component (inline-size > 30em) {
256+
.card { margin-inline: 2em; }
257+
}
258+
</pre>
259+
</div>
260+
261+
Issue: TODO: Implicit names based on container-type?
262+
Or a new syntax to query a specific container-type?
263+
264+
265+
<h3 id="container-shorthand">
266+
Creating Named Containers: the ''container'' shorthand</h2>
267+
268+
Issue: TODO: Define the container shorthand
269+
270+
Issue: TODO: Bikeshed terms (consider "query" or "context"?)
271+
272+
273+
<h3 id="container-rule">
274+
Container Queries: the ''@container'' rule</h2>
275+
276+
The <dfn at-rule id="at-ruledef-container">@container</dfn> rule
277+
is a [=conditional group rule=] whose condition is a container query.
278+
279+
To parse a <dfn>&lt;container-query-list></dfn> production,
280+
<a>parse a comma-separated list of component values</a>,
281+
then parse each entry in the returned list as a <<container-condition>>.
282+
283+
The syntax of a container condition in the ''@container'' rule
284+
is similar to that defined for <<media-condition>> in [[MEDIAQUERIES-4]].
285+
286+
The syntax of the ''@container'' rule is:
287+
288+
<pre class="prod def" nohighlight>
289+
@container <<container-name>>? <<container-query-list>> {
290+
<<stylesheet>>
291+
}
292+
</pre>
293+
294+
<h3 id="dimensional-container">
295+
Dimensional Container Features</h2>
296+
297+
Issue: TODO: Width queries
298+
299+
Issue: TODO: Height queries
300+
301+
Issue: TODO: Inline queries
302+
303+
Issue: TODO: Block queries
304+
305+
Issue: TODO: Aspect-ratio queries
306+
307+
Issue: TODO: Orientation queries
308+
309+
310+
<h3 id="style-container">
311+
Style Container Features</h2>
312+
313+
Issue: TODO: Custom property queries
314+
315+
Issue: TODO: Property queries (conflict with eg min/max-width dimensional queries?)
316+
317+
318+
<h3 id="state-container">
319+
State Container Features</h2>
320+
321+
Issue: TODO: Stuck?
322+
323+
Issue: TODO: Visible?
324+
325+
95326
Suppressing An Element's Contents Entirely: the 'content-visibility' property {#content-visibility}
96327
=================
97328

0 commit comments

Comments
 (0)