Skip to content

Commit 8c953b4

Browse files
authored
[css-anchor-position-1] Add justify/align-self:anchor-center value. #8979 (#9136)
1 parent 858f314 commit 8c953b4

File tree

1 file changed

+74
-9
lines changed

1 file changed

+74
-9
lines changed

css-anchor-position-1/Overview.bs

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ allowing multiple elements to use the same set of [=anchor functions=]
295295
(and [=position fallback lists=]!)
296296
while changing which [=anchor element=] each is referring to.
297297

298+
The [=target anchor element=] selected by the [=default anchor specifier=]
299+
(if one exists)
300+
is the element's <dfn>default anchor element</dfn>.
301+
298302
Its values are identical to the <<anchor-element>> term
299303
in ''anchor()'' and ''anchor-size()''.
300304

@@ -630,16 +634,77 @@ This has two effects:
630634
to find one that won't trigger overflow.
631635
</div>
632636

637+
<!--
638+
███ ██████ ████████ ██ ██ ████████ ████████ ████████
639+
██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██
640+
██ ██ ██ ██ ████ ██ ██ ██ ██ ██
641+
██ ██ ███████ ██ ██████ ██ ██ ██ ██ ██████ ████████
642+
█████████ ██ ██ ██ ████ ██ ██ ██ ██
643+
██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██
644+
██ ██ ██████ ████████ ██ ██ ██ ████████ ██ ██
645+
-->
646+
647+
<h2 id="anchor-center">
648+
Centering on the Anchor: the ''anchor-center'' value</h2>
649+
650+
<pre class=propdef>
651+
Name: justify-self, align-self, justify-items, align-items
652+
New Values: anchor-center
653+
</pre>
654+
655+
The [=self-alignment properties=] allow an [=absolutely-positioned=] element
656+
to align itself within the [=inset-modified containing block=].
657+
The existing values,
658+
plus carefully chosen [=inset properties=],
659+
are usually enough for useful alignment,
660+
but a common case for anchored positioning--
661+
centering over the anchor element--
662+
requires careful and somewhat complex set-up to achieve.
663+
664+
The new <dfn value for="justify-self, align-self, justify-items, align-items">anchor-center</dfn> value
665+
makes this case extremely simple:
666+
if the positioned element has a [=default anchor element=],
667+
then it is aligned so as to center itself
668+
over the [=default anchor element=]
669+
in the appropriate axis.
670+
If this alignment would cause it to overflow its [=inset-modified containing block=]
671+
in the appropriate axis,
672+
it instead is aligned flush with the side that it would have overflowed;
673+
if it would overflow both sides,
674+
it's instead aligned as for ''justify-self/start''.
675+
676+
Additionally,
677+
if both [=inset properties=] in the appropriate axis are ''top/auto'',
678+
they resolve to the offsets necessary
679+
to create the largest rectangle possible
680+
that is centered over the [=default anchor element=]
681+
and does not overflow the [=containing block=].
682+
If only one [=inset property=] is ''top/auto'',
683+
it resolves to ''0''.
684+
685+
Issue: See <a href="https://github.com/w3c/csswg-drafts/issues/9124">Issue 9124</a>
686+
about making this the behavior in general
687+
for non-''justify-self/auto'' alignment values.
688+
689+
If the element is not [=absolutely positioned=],
690+
or does not have a [=default anchor element=],
691+
this value behaves as ''center''
692+
and has no additional effect on how [=inset properties=] resolve.
693+
694+
Issue: Do we want to hook the "try to stay in the IMCB" behavior to safe vs unsafe?
695+
Right now it'll only trigger fallback if it overflows both sides;
696+
it might be useful to be able to trigger fallback
697+
as soon as it can't center itself.
633698

634699

635700
<!--
636-
███ ██████ ██████ ████████ ███████ ██ ██
637-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
638-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
639-
██ ██ ███████ ██████ ██ ████████ ██ ██ ██ ██
640-
█████████ ██ ██ ██ ██ ██ ██ ██ ██
641-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
642-
██ ██ ██████ ██████ ██ ██ ███████ ████████ ████████
701+
██████ ██████ ████████ ███████ ██ ██
702+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
703+
██ ██ ██ ██ ██ ██ ██ ██
704+
██████ ██ ████████ ██ ██ ██ ██
705+
██ ██ ██ ██ ██ ██ ██ ██
706+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
707+
██████ ██████ ██ ██ ███████ ████████ ████████
643708
-->
644709

645710
Taking Scroll Into Account {#scroll}
@@ -1255,7 +1320,7 @@ the ''@position-fallback'' rule:
12551320
<pre class='idl' export>
12561321
[Exposed=Window]
12571322
interface CSSPositionFallbackRule : CSSGroupingRule {
1258-
readonly attribute CSSOMString name;
1323+
readonly attribute CSSOMString name;
12591324
};
12601325
</pre>
12611326

@@ -1273,7 +1338,7 @@ declared in a ''@position-fallback'' rule:
12731338
<pre class='idl' export>
12741339
[Exposed=Window]
12751340
interface CSSTryRule : CSSRule {
1276-
[SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
1341+
[SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
12771342
};
12781343
</pre>
12791344

0 commit comments

Comments
 (0)