Skip to content
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

Editorial review: CSS anchor positioning 2: mostly association properties #33467

Merged
merged 52 commits into from
Jun 25, 2024

Conversation

chrisdavidmills
Copy link
Contributor

@chrisdavidmills chrisdavidmills commented May 7, 2024

Description

CSS Anchor Positioning is set to be released in Chrome 125 (see the associated Chrome Status entry).

This PR (part of a series; see the first PR here) adds the following content:

  • The HTML anchor attribute, used to declare the ID of an element that you want this element to be anchored to (i.e. its anchor element).
  • The Element.anchorElement property, used to access a reference to an element's anchor element.
  • The anchor-name property
  • The position-anchor property
  • The position-visibility property

Do not merge until #33058 is merged.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner May 7, 2024 11:23
@chrisdavidmills chrisdavidmills requested review from estelle and removed request for a team May 7, 2024 11:23
@chrisdavidmills chrisdavidmills marked this pull request as draft May 7, 2024 11:24
@github-actions github-actions bot added the Content:HTML Hypertext Markup Language docs label May 7, 2024
@chrisdavidmills chrisdavidmills removed the request for review from estelle May 7, 2024 11:24
@github-actions github-actions bot added the size/m [PR only] 51-500 LoC changed label May 7, 2024
Copy link
Contributor

github-actions bot commented May 7, 2024

Preview URLs (8 pages)
Flaws (27)

Note! 3 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/HTML/Global_attributes/anchor
Title: anchor
Flaw count: 1

  • macros:
    • /en-US/docs/Web/CSS/anchor does not exist

URL: /en-US/docs/Web/CSS/CSS_anchor_positioning
Title: CSS anchor positioning
Flaw count: 16

  • macros:
    • /en-US/docs/Web/CSS/anchor-scope does not exist
    • /en-US/docs/Web/CSS/inset-area does not exist
    • /en-US/docs/Web/CSS/position-try does not exist
    • /en-US/docs/Web/CSS/position-try-options does not exist
    • /en-US/docs/Web/CSS/position-try-order does not exist
    • and 3 more flaws omitted
  • broken_links:
    • Can't resolve /en-US/docs/Web/CSS/anchor
    • Can't resolve /en-US/docs/Web/CSS/anchor-size
    • Can't resolve /en-US/docs/Web/CSS/inset-area_function
    • Can't resolve /en-US/docs/Web/CSS/anchor#anchor-side
    • Can't resolve /en-US/docs/Web/CSS/anchor-size#anchor-size
    • and 3 more flaws omitted

URL: /en-US/docs/Web/CSS/position-anchor
Title: position-anchor
Flaw count: 4

  • macros:
    • /en-US/docs/Web/HTML/Element/anchor-name does not exist
    • /en-US/docs/Web/CSS/anchor does not exist
    • /en-US/docs/Web/CSS/inset-area does not exist
    • /en-US/docs/Web/CSS/anchor does not exist

URL: /en-US/docs/Web/CSS/anchor-name
Title: anchor-name
Flaw count: 3

  • macros:
    • /en-US/docs/Web/CSS/anchor does not exist
    • /en-US/docs/Web/CSS/inset-area does not exist
    • /en-US/docs/Web/CSS/anchor does not exist

URL: /en-US/docs/Web/CSS/position-visibility
Title: position-visibility
Flaw count: 3

  • macros:
    • /en-US/docs/Web/CSS/position-try-options does not exist
    • /en-US/docs/Web/CSS/@position-try does not exist
    • /en-US/docs/Web/CSS/inset-area does not exist
External URLs (2)

URL: /en-US/docs/Web/HTML/Global_attributes/anchor
Title: anchor


URL: /en-US/docs/Web/API/HTMLElement/anchorElement
Title: HTMLElement: anchorElement property

(comment last updated: 2024-06-25 11:14:56)

@github-actions github-actions bot added the Content:WebAPI Web API docs label May 7, 2024
@chrisdavidmills chrisdavidmills changed the title Add anchor attribute ref page CSS anchor positioning: mostly association properties May 7, 2024
@chrisdavidmills chrisdavidmills changed the title CSS anchor positioning: mostly association properties Tech review: CSS anchor positioning: mostly association properties May 7, 2024
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs size/l [PR only] 501-1000 LoC changed and removed size/m [PR only] 51-500 LoC changed labels May 7, 2024
@chrisdavidmills chrisdavidmills marked this pull request as ready for review May 8, 2024 10:32
@chrisdavidmills chrisdavidmills requested review from a team as code owners May 8, 2024 10:32
@chrisdavidmills chrisdavidmills requested review from sideshowbarker and dipikabh and removed request for a team May 8, 2024 10:32
@sideshowbarker sideshowbarker removed their request for review May 8, 2024 10:36
@chrisdavidmills chrisdavidmills changed the title Tech review: CSS anchor positioning: mostly association properties Tech review: CSS anchor positioning 2: mostly association properties May 8, 2024
mfreed7

This comment was marked as outdated.

@estelle

This comment was marked as outdated.

@github-actions github-actions bot added size/xl [PR only] >1000 LoC changed and removed size/l [PR only] 501-1000 LoC changed labels Jun 11, 2024
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEW:

APPROVED: HTMLElement.anchorElement property page
APPROVED: HTMLElementpage

anchor-name page:

has an issue in the description.
also suggested simplifications for the examples; removing border-radius and margin, and only using inset properties. This is one of the first pages people will read when learning this, so want to make it as simple as possible, so the only thing their confused about is anchor-name, anchor-position, and top/left/right/bottom.

position-anchor page:

  • remove the border-radius and margin on the examples
  • Is the space between the position-anchor and position intentional?
    Other than that, this is good to go.

Sumbitting this review, but will work on it again tomorrow.


## Browser compatibility

{{Compat}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, just a question: why does chrome say "canary" in blue and others just have flag with red X? If four browsers support it behind a flag, shouldn't they all appear somewhat similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure. Something to bring up with the BCD team?


## Description

To position an element relative to an anchor element, the positioned element requires three features: an association, a position, and a location. The `anchor-name` and {{cssxref("position-anchor")}} properties provide the association. The anchor element accepts one or more `<dashed-ident>` anchor names set on it via the `anchor-name` property. When one of those names is then set as the value of the positioned element's `position-anchor` property, the two elements are associated. The two elements become tethered by setting a {{cssxref("position")}} of `absolute` or `fixed` on the associated element, making it an "anchor-positioned" element.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To position an element relative to an anchor element, the positioned element requires three features: an association, a position, and a location. The `anchor-name` and {{cssxref("position-anchor")}} properties provide the association. The anchor element accepts one or more `<dashed-ident>` anchor names set on it via the `anchor-name` property. When one of those names is then set as the value of the positioned element's `position-anchor` property, the two elements are associated. The two elements become tethered by setting a {{cssxref("position")}} of `absolute` or `fixed` on the associated element, making it an "anchor-positioned" element.
To position an element relative to an anchor element, the positioned element requires three features: an association, a position, and a location. The `anchor-name` and {{cssxref("position-anchor")}} properties provide the association.
The anchor element accepts one or more `<dashed-ident>` anchor names set on it via the `anchor-name` property. When one of those names is then set as the value of the `position-anchor` property of an element that has its {{cssxref("position")}} set to `absolute` or `fixed`, the two elements are associated. The two elements become tethered by setting a location on the associated element relative to the anchor, making it an "anchor-positioned" element.

I think we may have gotten it wrong originally. If my 2nd paragraph edit is wrong, still add the paragraph return.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this is right; good catch.


Anchor positioning changes the [containing block](/en-US/docs/Web/CSS/Containing_block) of anchor-positioned elements, making its `position` relative to its anchor rather than to the nearest positioned ancestor element.

To tether and place a positioned element in a specific location relative to an anchor element, an anchor positioning feature is needed, such as the {{cssxref("anchor()")}} function (set as a value on {{glossary("inset properties")}}) or the {{cssxref("inset-area")}} property.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To tether and place a positioned element in a specific location relative to an anchor element, an anchor positioning feature is needed, such as the {{cssxref("anchor()")}} function (set as a value on {{glossary("inset properties")}}) or the {{cssxref("inset-area")}} property.
To tether and place a positioned element in a specific location relative to an anchor element, an anchor positioning feature is needed, such as the {{cssxref("anchor()")}} function (set within an {{glossary("inset properties", "inset property's")}} value) or the {{cssxref("inset-area")}} property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

text-shadow: 1px 1px 1px black;
background-color: hsl(240 100% 75%);
width: fit-content;
border-radius: 10px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
border-radius: 10px;

Let's kill the rounded corners so corners touch based on position.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said, I don't want to start messing with the example styling now; it will be a complete pain to keep consistent across all the new pages. If we really feel it is important after publication, let's do it as follow-up work.

I personally don't think this makes any difference.

Comment on lines 139 to 141
- {{cssxref("left")}} property to an {{cssxref("anchor()")}} function with a value of `right`, tethering the positioned element to it's anchor. This positions the infobox's left edge flush to the right edge of its anchor.
- {{cssxref("align-self")}} property to `anchor-center`, centrally aligning the infobox to the center of the anchor in the inline direction.
- {{cssxref("margin-left")}} to `10px`, creating space between the anchor positioned element and its anchor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- {{cssxref("left")}} property to an {{cssxref("anchor()")}} function with a value of `right`, tethering the positioned element to it's anchor. This positions the infobox's left edge flush to the right edge of its anchor.
- {{cssxref("align-self")}} property to `anchor-center`, centrally aligning the infobox to the center of the anchor in the inline direction.
- {{cssxref("margin-left")}} to `10px`, creating space between the anchor positioned element and its anchor.
- {{cssxref("left")}} and {{cssxref("top")}} properties to an {{cssxref("anchor()")}} function with a value of `right` and `top` respectively, tethering the positioned element to it's anchor. This positions the infobox's left edge flush to the right edge it's top edge flush to the top enge of its anchor.

let's omit margin and aligning center to keep this example as basic as possible; only including the features required and mentioned in the intro (we don't discuss align-self or anchor center)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't want to start editing the demos at this point; I just want to get this published. MDN readers are not stupid; including a couple of other properties won't destroy their understanding of the example. On the contrary, I think it is useful to introduce a couple of features that they might want to go on to learn more about.

Also, at the start of this example, we say "positioning the element to the right of the anchor" - this code is part of that positioning.

background-color: azure;
border: 1px solid #ddd;
padding: 10px;
border-radius: 10px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
border-radius: 10px;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change

Comment on lines +258 to +268
#infobox1 {
left: anchor(right);
align-self: anchor-center;
margin-left: 10px;
}

#infobox2 {
bottom: anchor(top);
justify-self: anchor-center;
margin-bottom: 15px;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#infobox1 {
left: anchor(right);
align-self: anchor-center;
margin-left: 10px;
}
#infobox2 {
bottom: anchor(top);
justify-self: anchor-center;
margin-bottom: 15px;
}
#infobox1 {
left: anchor(right);
top: anchor(top);
}
#infobox2 {
bottom: anchor(top);
right: anchor(right);
}

let's get rid of the border radius and centering. this makes it easier to understanding the example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No; I don't want to start fiddling with all the examples at this late stage.

}
```

Each of the two positioned elements are associated with the anchor element by setting its anchor name as the positioned element's {{cssxref("position-anchor")}} property value. Both are also given `fixed` positioning, making them **anchor positioned elements**. The positioned elements are then positioned in different places relative to the anchor using a combination of inset, alignment, and margin properties.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Each of the two positioned elements are associated with the anchor element by setting its anchor name as the positioned element's {{cssxref("position-anchor")}} property value. Both are also given `fixed` positioning, making them **anchor positioned elements**. The positioned elements are then positioned in different places relative to the anchor using a combination of inset, alignment, and margin properties.
Each of the two positioned elements are associated with the anchor element by setting its anchor name as the positioned element's {{cssxref("position-anchor")}} property value. Both are also given `fixed` positioning, making them **anchor positioned elements**. The positioned elements are then positioned in different places relative to the anchor using inset properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change

Comment on lines +328 to +346
.anchor {
font-size: 1.8rem;
color: white;
text-shadow: 1px 1px 1px black;
background-color: hsl(240 100% 75%);
width: fit-content;
border-radius: 10px;
border: 1px solid black;
padding: 3px;
}

.infobox {
color: darkblue;
background-color: azure;
border: 1px solid #ddd;
padding: 10px;
border-radius: 10px;
font-size: 1rem;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.anchor {
font-size: 1.8rem;
color: white;
text-shadow: 1px 1px 1px black;
background-color: hsl(240 100% 75%);
width: fit-content;
border-radius: 10px;
border: 1px solid black;
padding: 3px;
}
.infobox {
color: darkblue;
background-color: azure;
border: 1px solid #ddd;
padding: 10px;
border-radius: 10px;
font-size: 1rem;
}
.anchor {
font-size: 1.8rem;
color: white;
text-shadow: 1px 1px 1px black;
background-color: hsl(240 100% 75%);
width: fit-content;
border: 1px solid black;
padding: 3px;
}
.infobox {
color: darkblue;
background-color: azure;
border: 1px solid #ddd;
padding: 10px;
font-size: 1rem;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks long, but i just remove border radius

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hidden from the reader anyway, so it doesn't matter. No change.

Comment on lines +359 to +369
position-anchor: --anchor1;
left: anchor(right);
align-self: anchor-center;
margin-left: 10px;
}

#infobox2 {
position-anchor: --anchor2;
bottom: anchor(top);
justify-self: anchor-center;
margin-bottom: 15px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position-anchor: --anchor1;
left: anchor(right);
align-self: anchor-center;
margin-left: 10px;
}
#infobox2 {
position-anchor: --anchor2;
bottom: anchor(top);
justify-self: anchor-center;
margin-bottom: 15px;
position-anchor: --anchor1;
left: anchor(right);
top: anchor(top);
}
#infobox2 {
position-anchor: --anchor2;
bottom: anchor(top);
left: anchor(right);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no change

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few minor suggestions. Approving to not hold you up.

files/en-us/web/css/position-anchor/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/position-anchor/index.md Outdated Show resolved Hide resolved
```css
#infobox1 {
position-anchor: --myAnchor1;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these empty lines intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope; they look a bit weird. Removed!

files/en-us/web/css/position-anchor/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/position-anchor/index.md Outdated Show resolved Hide resolved

#### JavaScript

We dynamically change the `anchor-name` values set on the anchor elements in response to different anchors being selected in the positioned elements' `<select>` menus. The key functionality here is the [`change`](/en-US/docs/Web/API/HTMLElement/change_event) event handler, `updateAnchorNames()`. It sets both anchor names on one anchor, if the anchors chosen in the two `<select>` menus are the same. Otherwise, it sets a single anchor name on two separate anchors as appropriate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We dynamically change the `anchor-name` values set on the anchor elements in response to different anchors being selected in the positioned elements' `<select>` menus. The key functionality here is the [`change`](/en-US/docs/Web/API/HTMLElement/change_event) event handler, `updateAnchorNames()`. It sets both anchor names on one anchor, if the anchors chosen in the two `<select>` menus are the same. Otherwise, it sets a single anchor name on two separate anchors as appropriate.
We dynamically change which of the `.anchor` elements has an `anchor-name` value set on it in response to different anchors being selected in the positioned elements' `<select>` menus. The key functionality here is the [`change`](/en-US/docs/Web/API/HTMLElement/change_event) event handler, `updateAnchorNames()`. It sets both anchor names on one anchor, if the anchors chosen in the two `<select>` menus are the same. Otherwise, it sets a single anchor name on two separate anchors as appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see what you are getting at here, but it didn't seem quite right to me. I ended up changing the first sentence to:

We dynamically change which anchor elements the anchor-name values are set on in response to different anchors being selected in the positioned elements' <select> menus.

- `always`
- : The positioned element is always displayed.
- `anchors-visible`
- : If the anchor is completely hidden, either by overflowing its containing element (or the viewport) or being covered by other elements, the positioned element will be **strongly hidden**.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- : If the anchor is completely hidden, either by overflowing its containing element (or the viewport) or being covered by other elements, the positioned element will be **strongly hidden**.
- : If the anchor is completely hidden, either by overflowing its containing element (or the viewport) or being covered by other elements, the positioned element will be strongly hidden.

it's bold below, so we don't need to bold it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense; updated in next commit

Comment on lines 49 to 51
`position-visibility` should only be used in situations in which hiding the positioned element altogether is preferred. In most cases, it makes more sense to attempt to change the placement of positioned elements when they start to overflow, to keep them on-screen and usable. This can be be done with the {{cssxref("position-try-options")}} property and {{cssxref("@position-try")}} at-rule.

For detailed information on anchor features and usage, see the [CSS anchor positioning](/en-US/docs/Web/CSS/CSS_anchor_positioning) module landing page, the [Using CSS anchor positioning](/en-US/docs/Web/CSS/CSS_anchor_positioning/Using) guide, and [Handling overflow: try options and conditional hiding](/en-US/docs/Web/CSS/CSS_anchor_positioning/Try_options_hiding).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`position-visibility` should only be used in situations in which hiding the positioned element altogether is preferred. In most cases, it makes more sense to attempt to change the placement of positioned elements when they start to overflow, to keep them on-screen and usable. This can be be done with the {{cssxref("position-try-options")}} property and {{cssxref("@position-try")}} at-rule.
For detailed information on anchor features and usage, see the [CSS anchor positioning](/en-US/docs/Web/CSS/CSS_anchor_positioning) module landing page, the [Using CSS anchor positioning](/en-US/docs/Web/CSS/CSS_anchor_positioning/Using) guide, and [Handling overflow: try options and conditional hiding](/en-US/docs/Web/CSS/CSS_anchor_positioning/Try_options_hiding).
`position-visibility` should only be used in situations in which hiding the positioned element altogether is preferred. In most cases, it makes more sense to attempt to change the placement of positioned elements when they start to overflow, to keep them on-screen and usable. This can be be done with the {{cssxref("position-try-options")}} property and {{cssxref("@position-try")}} at-rule. See the [Handling overflow: try options and conditional hiding](/en-US/docs/Web/CSS/CSS_anchor_positioning/Try_options_hiding) for more information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

chrisdavidmills and others added 5 commits June 25, 2024 11:59
Co-authored-by: Estelle Weyl <estelle@openwebdocs.org>
Co-authored-by: Estelle Weyl <estelle@openwebdocs.org>
Co-authored-by: Estelle Weyl <estelle@openwebdocs.org>
Co-authored-by: Estelle Weyl <estelle@openwebdocs.org>
@chrisdavidmills chrisdavidmills merged commit 19748cf into mdn:main Jun 25, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs Content:HTML Hypertext Markup Language docs Content:WebAPI Web API docs size/xl [PR only] >1000 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants