Skip to content

Commit 99403a8

Browse files
committed
[css-anchor-position] Make base styles *not* part of the position options list, so it's not affected by position-try-order sorting.
1 parent 29bbdac commit 99403a8

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

css-anchor-position-1/Overview.bs

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ This property provides a list of alternate positioning styles
10251025
to try when the [=absolutely positioned box=]
10261026
overflows its [=inset-modified containing block=].
10271027
This <dfn export>position options list</dfn>
1028-
initially contains the element's own computed style.
1028+
is initially empty.
10291029

10301030
Each comma-separated entry in the list is a separate option:
10311031
either the name of a ''@position-try'' block,
@@ -1037,8 +1037,7 @@ Values have the following meanings:
10371037
: <dfn>none</dfn>
10381038
::
10391039
The property has no effect;
1040-
the only entry in the [=position options list=]
1041-
is the element's computed style.
1040+
the element's [=position options list=] is empty.
10421041

10431042
: <dfn><<dashed-ident>></dfn>
10441043
::
@@ -1128,12 +1127,61 @@ the [=position options list=] will be tried.
11281127
: <dfn>most-block-size</dfn>
11291128
: <dfn>most-inline-size</dfn>
11301129
::
1131-
Stable sort the [=position options list=]
1132-
in order of greatest to least
1133-
[=inset-modified containing block=] size
1134-
in the matching axis.
1130+
For each entry in the [=position options list=],
1131+
[=determine the position fallback styles=],
1132+
and find the specified [=inset-modified containing block=] size
1133+
that results from those styles.
1134+
Stably sort the [=position options list=]
1135+
according to this size,
1136+
with the largest coming first.
11351137
</dl>
11361138

1139+
<div class=example>
1140+
For example, the following styles
1141+
will initially position the popup list below its anchoring button,
1142+
but if that overflows,
1143+
will decide whether to keep the popup list below the anchor
1144+
or move it above,
1145+
depending on which option gives it the most space.
1146+
1147+
<pre highlight=css>
1148+
.anchor { anchor-name: --foo; }
1149+
.list {
1150+
position: fixed;
1151+
anchor-default: --foo;
1152+
top: anchor(bottom);
1153+
left: anchor(left);
1154+
align-self: start;
1155+
position-try-options: --bottom-scrollable, flip-block, --top-scrollable;
1156+
position-try-order: most-height;
1157+
}
1158+
@position-try --bottom-scrollable {
1159+
top: anchor(bottom);
1160+
bottom: 0;
1161+
align-self: stretch;
1162+
}
1163+
@position-try --top-scrollable {
1164+
bottom: anchor(top);
1165+
top: 0;
1166+
align-self: stretch;
1167+
}
1168+
</pre>
1169+
1170+
The ''flip-block'' auto-generated option and the ''--top-scrollable'' option
1171+
will always find the same available height,
1172+
since both of them stretch vertically from ''top: 0''
1173+
(the top edge of the viewport)
1174+
to ''bottom: anchor(top)''
1175+
(the top of the anchor),
1176+
so they'll retain their specified order.
1177+
This causes the element to first try to align against the anchor
1178+
at its natural height
1179+
(using ''align-self: end'', auto-reversed from the base styles),
1180+
but if that also causes overflow,
1181+
it'll fall back to just filling the space
1182+
and being scrollable instead.
1183+
</div>
1184+
11371185
Final Fallback Strategy: the 'position-try-final' property {#position-try-final-property}
11381186
----------------------
11391187

@@ -1322,7 +1370,8 @@ Animation type: discrete
13221370
Applying Position Fallback {#fallback-apply}
13231371
--------------------------
13241372

1325-
When an element uses a [=position options list=],
1373+
When a positioned element overflows its [=inset-modified containing block=],
1374+
and has a non-empty [=position options list=],
13261375
it selects one entry from the list
13271376
as defined below,
13281377
and applies those properties to itself as [=used values=].

0 commit comments

Comments
 (0)