Skip to content

Commit 7bbb002

Browse files
committed
[css-conditional-5] Draft spec for scroll-state() w3c#6402
Per resolution in [1], add scroll-state() as a query function to query sticky, snap, and overflow scroll states with a new container-type for scroll-state queries. [1] w3c#6402 (comment)
1 parent 2be3d9a commit 7bbb002

File tree

1 file changed

+107
-16
lines changed

1 file changed

+107
-16
lines changed

css-conditional-5/Overview.bs

+107-16
Original file line numberDiff line numberDiff line change
@@ -460,28 +460,20 @@ Creating Query Containers: the 'container-type' property</h3>
460460

461461
<pre class='propdef'>
462462
Name: container-type
463-
Value: normal | size | inline-size
463+
Value: normal | [ [ size | inline-size ] || scroll-state ]
464464
Initial: normal
465465
Inherited: no
466466
Applies to: all elements
467467
Computed value: specified keyword
468468
Animation type: not animatable
469469
</pre>
470470

471-
The 'container-type' property establishes the element
472-
as a <dfn export>query container</dfn>
473-
for the purpose of [=container queries=] that require explicit containment
474-
(such as [=container size queries=]),
475-
allowing [=style rules=] styling its descendants
476-
to query various aspects of its sizing and layout,
477-
and respond accordingly.
478-
479-
Unless otherwise noted,
480-
all elements are [=query containers=]
481-
for the purpose of [=container queries=]
482-
that do not require explicit [=containment=]
483-
(such as [=container style queries=]),
484-
regardless of the specified 'container-type'.
471+
The 'container-type' property establishes the element as a
472+
<dfn export>query container</dfn> for certain types of queries. For size
473+
[=container queries=], that require certain types of containment, elements
474+
are explicitly made [=query containers=] through this property. For other
475+
types of [=query containers=] any element can be a query container, such as
476+
for [=container style queries=].
485477

486478
Values have the following meanings:
487479

@@ -502,10 +494,13 @@ Creating Query Containers: the 'container-type' property</h3>
502494
[=style containment=],
503495
and [=inline-size containment=]
504496
to the [=principal box=].
497+
<dt><dfn>scroll-state</dfn>
498+
<dd>
499+
Establishes a [=query container=] for [=scroll-state queries=]
505500
<dt><dfn>normal</dfn>
506501
<dd>
507502
The element is not a [=query container=]
508-
for any [=container size queries=],
503+
for any [=container size queries=] or [=scroll-state queries=],
509504
but remains a [=query container=] for [=container style queries=].
510505
</dl>
511506

@@ -546,6 +541,23 @@ Creating Query Containers: the 'container-type' property</h3>
546541
</pre>
547542
</div>
548543

544+
<div class=example>
545+
Containers can also expose state that depend on scroll offset. Here is an
546+
example of how to style a descendant of a sticky positioned element when it
547+
is stuck to the top edge:
548+
549+
<pre class=lang-css>
550+
#sticky {
551+
container-type: scroll-state;
552+
position: sticky;
553+
}
554+
@container style(stuck: top) {
555+
#sticky-child {
556+
background-color: lime;
557+
}
558+
}
559+
</pre>
560+
</div>
549561

550562
<h3 id="container-name">
551563
Naming Query Containers: the 'container-name' property</h3>
@@ -1067,6 +1079,85 @@ Style Container Features</h3>
10671079
are [=computed value|computed=] with respect to the [=query container=],
10681080
the same as other values.
10691081

1082+
<h3 id="scroll-state-container">
1083+
Scroll State Container Features</h3>
1084+
1085+
A <dfn export>container scroll-state query</dfn> allows to query a container about various
1086+
state state that depends on scroll position.
1087+
1088+
<h4 id="stuck">
1089+
Sticky positioning: the '@container/stuck' feature</h4>
1090+
1091+
<pre class="descdef mq">
1092+
Name: stuck
1093+
For: @container
1094+
Value: top | right | bottom | left | inset-block-start | inset-inline-start | inset-block-end | inset-inline-end
1095+
Type: discrete
1096+
</pre>
1097+
1098+
The '@container/stuck' [=container feature=] queries whether a
1099+
''position/sticky'' positioned container is visually shifted to stay inside
1100+
the [=sticky view rectangle=] for the given edge. The logical edges maps to
1101+
physical based on the direction and writing-mode of the [=query container=].
1102+
1103+
In the boolean context, the query matches if visual shift is applied in any
1104+
direction.
1105+
1106+
<dl dfn-type=value dfn-for="@container/stuck">
1107+
<dt><dfn>top</dfn>
1108+
<dd>
1109+
The ''position/sticky'' container is shifted to stay inside the top edge.
1110+
<dt><dfn>right</dfn>
1111+
<dd>
1112+
The ''position/sticky'' container is shifted to stay inside the right edge.
1113+
<dt><dfn>bottom</dfn>
1114+
<dd>
1115+
The ''position/sticky'' container is shifted to stay inside the bottom edge.
1116+
<dt><dfn>left</dfn>
1117+
<dd>
1118+
The ''position/sticky'' container is shifted to stay inside the left edge.
1119+
<dt><dfn>inset-block-start</dfn>
1120+
<dd>
1121+
The ''position/sticky'' container is shifted to stay inside the inset-block-start edge.
1122+
<dt><dfn>inset-inline-start</dfn>
1123+
<dd>
1124+
The ''position/sticky'' container is shifted to stay inside the inset-inline-start edge.
1125+
<dt><dfn>inset-block-end</dfn>
1126+
<dd>
1127+
The ''position/sticky'' container is shifted to stay inside the inset-block-end edge.
1128+
<dt><dfn>inset-inline-end</dfn>
1129+
<dd>
1130+
The ''position/sticky'' container is shifted to stay inside the inset-inline-end edge.
1131+
</dl>
1132+
1133+
<h4 id="snapped">
1134+
Scroll snapping: the '@container/snapped' feature</h4>
1135+
1136+
<pre class="descdef mq">
1137+
Name: snapped
1138+
For: @container
1139+
Value: block | inline
1140+
Type: discrete
1141+
</pre>
1142+
1143+
The '@container/snapped' [=container feature=] queries whether a [=snap target=]
1144+
is snapped to its [=snap container=] in the given axis. It matches in the boolean
1145+
context it is snapped in at least one of the directions.
1146+
1147+
<dl dfn-type=value dfn-for="@container/snapped">
1148+
<dt><dfn>block</dfn>
1149+
<dd>
1150+
'@container/snapped' [=container feature=] matches ''block''
1151+
if the container is a [=snap target=] for its [=snap container=]
1152+
in the block direction of the [=snap container=].
1153+
<dt><dfn>inline</dfn>
1154+
<dd>
1155+
'@container/snapped' [=container feature=] matches ''inline''
1156+
if the container is a [=snap target=] for its [=snap container=]
1157+
in the inline direction of the [=snap container=].
1158+
</dl>
1159+
1160+
10701161
<h2 id="container-lengths">
10711162
Container Relative Lengths: the ''cqw'', ''cqh'', ''cqi'', ''cqb'', ''cqmin'', ''cqmax'' units</h2>
10721163

0 commit comments

Comments
 (0)