Skip to content

[css-anchor-position] Default alignment in center track. #11803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fantasai opened this issue Feb 28, 2025 · 3 comments
Closed

[css-anchor-position] Default alignment in center track. #11803

fantasai opened this issue Feb 28, 2025 · 3 comments

Comments

@fantasai
Copy link
Collaborator

If the only the center region in an axis is selected, or all three regions are selected, the default alignment in that axis is anchor-center.

I'm wondering if the default alignment in the center track should be center instead of anchor-center.

This makes a difference if the author applies asymmetric insets, e.g. given a 100px anchor, suppose there's a 10px inset on the right. Should the item be centered against the entire anchor, or against the inset area?

I suspect the answer should be the inset area, i.e. center. @kizu wdyt?

@kizu
Copy link
Member

kizu commented Feb 28, 2025

Mmm, I don't have a strong preference for either.

Quickly testing: https://codepen.io/kizu/pen/qEBRjzo?editors=1100

On the left — anchor-center, on the right — center.

A screenshot of the CodePen above. It shows a 2 by 2 grid with first row having small anchor width and the anchored element shrinking, and second row shows a wide anchor, with the anchored element being wide. In the left column the anchored element is always centered, in the right column it is offset, and in the first row it is not visually connected to the anchor.

If the inset is larger than the width of the anchor, then I prefer anchor-center. With an anchor larger than the positioned element, I can see how you could want to express that shift from the side. At the same time, you could also use margin for this, which will be, while slightly different, the same for both cases.

If there are actual use cases where this plays a role, we can change it. Otherwise, given this is just a default that can be changed, and I don't see a big effect from the change, I'd stick with the anchor-center for all these cases just for consistency (but, again, no strong preference).

@fantasai
Copy link
Collaborator Author

By default, anchor-center is not supposed to draw outside the inset-modified area -- Chrome has a bug here.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [css-anchor-position] Default alignment in center track., and agreed to the following:

  • RESOLVED: Default alignment in the center track (single track), default alignment is 'center' not 'anchor-center'.
The full IRC log of that discussion <TabAtkins> fantasai: i think we got the default alginment wrong for the center track
<TabAtkins> fantasai: you can be in the center track, or span two, or span all three
<TabAtkins> fantasai: with all three, you want anchor-center by default so you're connected to the anchor
<TabAtkins> fantasai: but when you're just in the center track, anchor-center tries to put you centered on the anchor even if you specify an inset
<TabAtkins> fantasai: if you are using an inset, tho, usually that means you're compensating for something
<TabAtkins> fantasai:
<TabAtkins> fantasai: so i think it makes more sense to actually center when we're in just the center track
<TabAtkins> fantasai: kizu posted an example where using center looks weird with the insets, but i think that's actually another bug in chrome, where anchor-center isn't paying attention to the insets properly
<kizu> q+
<fantasai> This makes a difference if the author applies asymmetric insets, e.g. given a 100px anchor, suppose there's a 10px inset on the right. Should the item be centered against the entire anchor, or against the inset area?
<astearns> ack kizu
<kizu> https://github.com//issues/12020
<TabAtkins> kizu: i think i prefer to account for inset-area more
<TabAtkins> kizu: if you're compensating for the dimensions of something, we should honor that
<TabAtkins> fantasai: [example time]
<TabAtkins> fantasai: anchor element, with two bits, a main and a extra bit on the right
<TabAtkins> fantasai: i want my abspos to be below the anchor
<TabAtkins> fantasai: i want to compensate for the right bit, i'm not centering on that
<TabAtkins> fantasai: so use some `right: 10px` to shrink my area to match excluding the right bit of the anchor
<TabAtkins> fantasai: so now my IMCB is a little smaller, centered on the "main" bit of the anchor that I want
<TabAtkins> fantasai: i think it should center in that remaining space
<TabAtkins> fantasai: current spec says to use anchor-center
<TabAtkins> fantasai: which'll ignore the insets, it's caring about the anchor itself not the IMCB
<TabAtkins> fantasai: so I think if the author is explicitly using an inset we should pay attention to that. default shoudl be center, not anchor-center
<bkardell> sounds reasonable
<fantasai> TabAtkins: In the overflow case, where abspos is larger than the IMCB.
<fantasai> TabAtkins: you're saying that it's a chrome bug?
<fantasai> fantasai: Yeah, it'll center against the anchor box, ignoring the insets
<fantasai> fantasai: and I think it should honor the insets
<TabAtkins> (in other words, it should decenter when it's wide enough to hit one edge of the IMCB)
<fantasai> TabAtkins: I don't think I have a strong opinion. Ian, do you have any compat concerns?
<fantasai> iank_: probably compat wise is fine, early enough
<fantasai> iank_: people are usually using top/bottom, not center
<fantasai> astearns: Roman, sounds ok?
<fantasai> TabAtkins: we're basically showing off his example
<fantasai> PROPOSED: Default alignment in the center track (single track), default alignment is 'center' not 'anchor-center'.
<fantasai> RESOLVED: Default alignment in the center track (single track), default alignment is 'center' not 'anchor-center'.

fantasai added a commit to fantasai/WebKit that referenced this issue Apr 21, 2025
…nter tracks

https://bugs.webkit.org/show_bug.cgi?id=291863

Reviewed by NOBODY (OOPS!).

CSSWG recently changed the default alignment of the center track from
anchor-center to center, so this updates defaultAlignmentForAxis accordingly.
See w3c/csswg-drafts#11803

* LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-align-justify-wm-dir.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-align-justify.html:
* Source/WebCore/rendering/style/PositionArea.cpp:
(WebCore::PositionArea::defaultAlignmentForAxis const):
fantasai added a commit to fantasai/WebKit that referenced this issue Apr 22, 2025
https://bugs.webkit.org/show_bug.cgi?id=291863
rdar://149715581

Reviewed by NOBODY (OOPS!).

CSSWG recently changed the default alignment of the center track from
anchor-center to center, so this updates defaultAlignmentForAxis() accordingly.
See w3c/csswg-drafts#11803

* LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-align-justify-wm-dir.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-align-justify.html:
* Source/WebCore/rendering/style/PositionArea.cpp:
(WebCore::PositionArea::defaultAlignmentForAxis const):
webkit-commit-queue pushed a commit to fantasai/WebKit that referenced this issue Apr 22, 2025
https://bugs.webkit.org/show_bug.cgi?id=291863
rdar://149715581

Reviewed by Anne van Kesteren.

CSSWG recently changed the default alignment of the center track from
anchor-center to center, so this updates defaultAlignmentForAxis() accordingly.
See w3c/csswg-drafts#11803

* LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-align-justify-wm-dir.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-align-justify.html:
* Source/WebCore/rendering/style/PositionArea.cpp:
(WebCore::PositionArea::defaultAlignmentForAxis const):

Canonical link: https://commits.webkit.org/293961@main
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 24, 2025
…lignment in center track, a=testonly

Automatic update from web-platform-tests
[css-anchor-position-1] Update default alignment in center track

w3c/csswg-drafts#11803

--

wpt-commits: d4431118f031349669986c25cc5d460cde3e0877
wpt-pr: 52098
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this issue Apr 29, 2025
…lignment in center track, a=testonly

Automatic update from web-platform-tests
[css-anchor-position-1] Update default alignment in center track

w3c/csswg-drafts#11803

--

wpt-commits: d4431118f031349669986c25cc5d460cde3e0877
wpt-pr: 52098
shtrom pushed a commit to mozilla-firefox/infra-testing that referenced this issue Apr 29, 2025
…lignment in center track, a=testonly

Automatic update from web-platform-tests
[css-anchor-position-1] Update default alignment in center track

w3c/csswg-drafts#11803

--

wpt-commits: d4431118f031349669986c25cc5d460cde3e0877
wpt-pr: 52098
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue May 1, 2025
…lignment in center track, a=testonly

Automatic update from web-platform-tests
[css-anchor-position-1] Update default alignment in center track

w3c/csswg-drafts#11803

--

wpt-commits: d4431118f031349669986c25cc5d460cde3e0877
wpt-pr: 52098

UltraBlame original commit: e5e811c5f392be737892959bf99260025691237b
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue May 1, 2025
…lignment in center track, a=testonly

Automatic update from web-platform-tests
[css-anchor-position-1] Update default alignment in center track

w3c/csswg-drafts#11803

--

wpt-commits: d4431118f031349669986c25cc5d460cde3e0877
wpt-pr: 52098

UltraBlame original commit: e5e811c5f392be737892959bf99260025691237b
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue May 1, 2025
…lignment in center track, a=testonly

Automatic update from web-platform-tests
[css-anchor-position-1] Update default alignment in center track

w3c/csswg-drafts#11803

--

wpt-commits: d4431118f031349669986c25cc5d460cde3e0877
wpt-pr: 52098

UltraBlame original commit: e5e811c5f392be737892959bf99260025691237b
@fantasai fantasai closed this as completed May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Thursday Afternoon
Development

No branches or pull requests

3 participants