Skip to content

Commit 6180d79

Browse files
lillestabatkins
andauthored
[css-anchor-position-2] Add the 'anchored' container-type w3c#12390 (w3c#12672)
* [css-anchor-position-2] Add the 'anchored' container-type w3c#12390 Create delta spec with the added container-type per resolution in: w3c#12390 (comment) * Update css-anchor-position-2/Overview.bs --------- Co-authored-by: Tab Atkins Jr. <jackalmage@gmail.com>
1 parent 7a96575 commit 6180d79

File tree

1 file changed

+210
-0
lines changed

1 file changed

+210
-0
lines changed

css-anchor-position-2/Overview.bs

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<pre class='metadata'>
2+
Title: CSS Anchor Positioning Level 2
3+
Shortname: css-anchor-position
4+
Level: 2
5+
!Delta Spec: yes
6+
Status: ED
7+
Prepare for TR: no
8+
Group: csswg
9+
Work Status: exploring
10+
ED: https://drafts.csswg.org/css-anchor-position-2/
11+
TR: https://www.w3.org/TR/css-anchor-position-2/
12+
Editor: Tab Atkins-Bittner, Google, http://xanthir.com/contact/, w3cid 42199
13+
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
14+
Editor: Ian Kilpatrick, Google, w3cid 73001
15+
16+
Abstract: This specification defines [=anchor positioning=],
17+
where an positioned element can size and position itself
18+
relative to one or more anchor elements elsewhere on the page.
19+
</pre>
20+
21+
22+
<h2 id="delta">Delta specification</h2>
23+
24+
This is a delta specification, meaning that it currently contains
25+
only the differences from CSS Anchor Positioning Level 1 [[!CSS-ANCHOR-POSITION-1]].
26+
27+
<h2 id="anchored-container-queries">Container Queries for Anchor Positioning</h2>
28+
29+
This section extends [=container queries=] from [[css-conditional-5]] to allow
30+
querying certain aspects of elements using [=anchor positioning=].
31+
32+
<h3 id="container-type-anchored">Extending 'container-type' with ''anchored''</h3>
33+
34+
This specification extends the ''container-type'' property defined in
35+
[[css-conditional-5#container-type]] with a new ''anchored'' keyword.
36+
''anchored'' can be combined with existing container types such as
37+
''container-type/scroll-state'' and ''container-type/size'':
38+
39+
<pre class="prod">normal | [ [ size | inline-size ] || scroll-state || anchored ]</pre>
40+
41+
<dl dfn-type=value dfn-for=container-type>
42+
<dt><dfn>anchored</dfn>
43+
<dd>
44+
Establishes a [=query container=] for [=container queries=],
45+
allowing for descendants of an anchor positioned element to be styled
46+
based on certain features of the anchoring.
47+
(Currently, limited to which of the 'position-try-fallbacks' are applied, if any.)
48+
49+
The ''anchored'' container-type applies [=style containment=] to the
50+
[=query container=].
51+
52+
<div class=note>
53+
NOTE: [=Style containment=] is necessary to avoid a layout cycle for the
54+
following case using [=counters=]:
55+
- We have an ''anchored'' container
56+
- A [=counter=] is incremented by a descendant of the anchored container
57+
based on a fallback query.
58+
- An [=in-flow=] element, following the anchored container in tree order,
59+
generates content, with the counter, affecting the size of the [=in-flow=]
60+
element.
61+
- The [=in-flow=] element affects the position / size of the
62+
<l spec=css-anchor-position-1>[=anchor element=]</l>. In fact,
63+
the [=in-flow=] may be the <l spec=css-anchor-position-1>[=anchor element=]</l>
64+
itself.
65+
- The changed position / size of the <l spec=css-anchor-position-1>[=anchor element=]</l>
66+
may change which fallback is chosen, which in turn affects the anchored query evaluation,
67+
hence the counter increment.
68+
</div>
69+
</dl>
70+
71+
<div class=example>
72+
A container can be just ''anchored'', or combined with other container types:
73+
74+
<pre class=lang-css>
75+
#anchored { container-type: anchored; }
76+
#anchored-size { container-type: anchored inline-size; }
77+
</pre>
78+
</div>
79+
80+
<h3 id="container-rule-anchored">Extending ''@container'' syntax for ''anchored'' queries</h3>
81+
82+
To query an ''anchored'' container, a new <code>anchored()</code> function is
83+
added to the ''@container'' syntax. It extends the container query syntax by adding the
84+
following production to the '<<query-in-parens>>' grammar:
85+
86+
<pre class="prod def">
87+
<<query-in-parens>> = ...
88+
| anchored( <<anchored-query>> )
89+
90+
<dfn><<anchored-query>></dfn> = not <<anchored-in-parens>>
91+
| <<anchored-in-parens>> [ [ and <<anchored-in-parens>> ]* | [ or <<anchored-in-parens>> ]* ]
92+
| <<anchored-feature>>
93+
<dfn><<anchored-in-parens>></dfn> = ( <<anchored-query>> )
94+
| ( <<anchored-feature>> )
95+
| <<general-enclosed>>
96+
</pre>
97+
98+
<h3 id="anchored-container">Anchored Container Features</h3>
99+
100+
<h4 id="anchored">
101+
Applied 'position-try-fallbacks': the '@container/fallback' feature</h4>
102+
103+
<pre class="descdef mq">
104+
Name: fallback
105+
For: @container
106+
Value: none | [ [<<dashed-ident>> || <<try-tactic>>] | <<position-area>> ]
107+
Type: discrete
108+
</pre>
109+
110+
The '@container/fallback' [=container feature=] queries whether an anchor
111+
positioned element has any of its computed 'position-try-fallbacks' options
112+
applied.
113+
114+
<dl dfn-type=value dfn-for="@container/fallback">
115+
<dt><dfn>none</dfn>
116+
<dd>
117+
The ''container-type/anchored'' container does not have any 'position-try-fallbacks'
118+
applied.
119+
<dt><<dashed-ident>> || <<try-tactic>></dt>
120+
<dd>
121+
The ''container-type/anchored'' container matches a combination of
122+
<<dashed-ident>> and <<try-tactic>> applied from 'position-try-fallbacks'.
123+
If any of the ''<<dashed-ident>>'' or ''<<try-tactic>>'' are left out of
124+
the query value, they need to be left out in the applied value from
125+
'position-try-fallbacks', and vice versa, in order to match.
126+
127+
The ''<<dashed-ident>>'' try rule name is not considered to be a
128+
[=tree-scoped name=] for the sake of matching '@container/fallback'.
129+
130+
The order of <<try-tactic>>s is significant. For instance
131+
<code>flip-start flip-block</code> is not the same as
132+
<code>flip-block flip-start</code>. Hence, the order must match for
133+
'@container/fallback' queries.
134+
<dt><<position-area>></dt>
135+
<dd>
136+
The ''container-type/anchored'' container has a ''<<position-area>>''
137+
applied from 'position-try-fallbacks'. The query matches if the applied
138+
''<<position-area>>'' from the fallback and the query value represent the
139+
same physical area. That is, ''position-area/block-start'' will match
140+
''position-area/top'' when the 'writing-mode' is ''writing-mode/horizontal-tb''.
141+
</dl>
142+
143+
<div class=example>
144+
Add an arrow whose direction depends on whether an element is positioned to
145+
the left or right of its anchor:
146+
147+
<pre class=lang-css>
148+
#container {
149+
container-type: anchored;
150+
position: absolute;
151+
position-anchor: --a;
152+
position-area: left;
153+
position-try-fallbacks: right;
154+
&::before { content: ">"; }
155+
156+
@container anchored(fallback: right) {
157+
&::before { content: "<"; };
158+
}
159+
}
160+
</pre>
161+
</div>
162+
163+
<div class=example>
164+
Matching named fallback option with '<<try-tactic>>':
165+
166+
<pre class=lang-css>
167+
.anchored {
168+
container-type: anchored;
169+
position-try-fallbacks: --foo, --bar flip-inline;
170+
171+
@container anchored(fallback: --bar flip-inline) {
172+
/* Applies if the '--bar' fallback applies */
173+
.inner { background-color: green; }
174+
}
175+
@container anchored(fallback: --bar) {
176+
/* Does not apply because the try-tactic also must match */
177+
.inner { background-color: red; }
178+
}
179+
}
180+
</pre>
181+
</div>
182+
183+
<div class=example>
184+
Matching named fallback option with '<<position-area>>' in vertical 'writing-mode':
185+
186+
<pre class=lang-css>
187+
.anchored {
188+
container-type: anchored;
189+
position-anchor: --a;
190+
position-try-fallbacks: right;
191+
writing-mode: vertical-rl;
192+
193+
@container anchored(fallback: self-block-start) {
194+
/* Applies if the 'right' fallback applies since block-start is 'right'
195+
in 'vertical-rl'. */
196+
.inner { background-color: green; }
197+
}
198+
}
199+
</pre>
200+
</div>
201+
202+
Security Considerations {#sec}
203+
=======================
204+
205+
No Security issues have been raised against this document.
206+
207+
Privacy Considerations {#priv}
208+
======================
209+
210+
No Privacy issues have been raised against this document.

0 commit comments

Comments
 (0)