-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Editorial review: Document anchor-scope property #42227
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
Changes from 1 commit
ce29ef1
a2d15ec
6bc0d77
ea31cf4
b625e6f
038752b
7988951
e4af5bd
91f8a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,296 @@ | ||||||
| --- | ||||||
| title: anchor-scope | ||||||
| slug: Web/CSS/Reference/Properties/anchor-scope | ||||||
| page-type: css-property | ||||||
| browser-compat: css.properties.anchor-scope | ||||||
| sidebar: cssref | ||||||
| --- | ||||||
|
|
||||||
| The **`anchor-scope`** [CSS](/en-US/docs/Web/CSS) property can be used to limit the scope of the DOM within which positioned elements can be associated with anchor elements to a particular subtree. | ||||||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ## Syntax | ||||||
|
|
||||||
| ```css | ||||||
| /* Single values */ | ||||||
| anchor-scope: none; | ||||||
| anchor-scope: all; | ||||||
| anchor-scope: --anchor-name; | ||||||
|
|
||||||
| /* Multiple <dashed-ident> values */ | ||||||
| anchor-scope: --anchor-name, --another-name; | ||||||
|
|
||||||
| /* Global values */ | ||||||
| anchor-scope: inherit; | ||||||
| anchor-scope: initial; | ||||||
| anchor-scope: revert; | ||||||
| anchor-scope: revert-layer; | ||||||
| anchor-scope: unset; | ||||||
| ``` | ||||||
|
|
||||||
| ### Values | ||||||
|
|
||||||
| - `none` | ||||||
| - : The default value. No anchor scope limiting happens on an element when this value is set. | ||||||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - `all` | ||||||
| - : Any {{cssxref("anchor-name")}}s declared on an element with this value set and its descendants can only be bound to by positioned elements that are descendants of the same element. | ||||||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - {{cssxref("dashed-ident")}}# | ||||||
| - : One or more comma-separated {{cssxref("dashed-ident")}}s representing anchor names. Any of the specified `anchor-name`s declared on an element with this value set and its descendants can only be bound to by positioned elements that are descendants of the same element. | ||||||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ## Description | ||||||
|
|
||||||
| When multiple anchor elements on a page are given the same {{cssxref("anchor-name")}} value and a positioned element is associated with that anchor name (by specifying the name as its {{cssxref("position-anchor")}} property value), the positioned element will be associated with the _last_ anchor element in the source order with that anchor name. | ||||||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| This can be a problem in certain situations. For example, when you have multiple HTML components repeated on a page, and each one features a positioned element anchored to the component, all of the positioned elements will be anchored to the last component on the page, unless each component uses a different anchor name. | ||||||
|
|
||||||
| The `anchor-scope` property can fix this problem by making it so that each positioned element can only be anchored to an element within the same subtree of the element that has the scope set on it: | ||||||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| - `anchor-scope: all` sets the scope so that _any_ `anchor-name` values set in the subtree can only be bound to by positioned elements in the same subtree. | ||||||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - `anchor-scope: <dashed-ident>#` sets the scope so that the specified `anchor-name` values, when set in the subtree, can only be bound to by positioned elements in the same subtree. | ||||||
|
|
||||||
| If you have, for example, three `anchor-name` values set inside a subtree (say, <code>‑‑anchor1</code>, <code>‑‑anchor2</code>, and <code>‑‑anchor3</code>), setting <code>anchor-scope: ‑‑anchor1, ‑‑anchor2, ‑‑anchor3</code> on the top-level element of the subtree would be equivalent to setting `anchor-scope: all`. | ||||||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| If you have, for example, three `anchor-name` values set inside a subtree (say, <code>‑‑anchor1</code>, <code>‑‑anchor2</code>, and <code>‑‑anchor3</code>), setting <code>anchor-scope: ‑‑anchor1, ‑‑anchor2, ‑‑anchor3</code> on the top-level element of the subtree would be equivalent to setting `anchor-scope: all`. | |
| If you have, for example, three `anchor-name` values set inside a subtree (say, `‑‑anchor1`, `‑‑anchor2`, and `‑‑anchor3`), setting `anchor-scope: ‑‑anchor1, ‑‑anchor2, ‑‑anchor3` on the top-level element of the subtree would be equivalent to setting `anchor-scope: all`. |
I used non-breaking hyphens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've gone through and replaced them all with regular dashes and backticks. I think your reasoning about the non-breaking dashes being invalid (and therefore causing problems if people decide to copy and paste them) is the main argument that has convinced me.
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this 50% opaque so when they're on top of each other, the numbers (that we changed per the recommended edits in the HTML) show thru and you can really see they're on top of each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried it, and TBH, it doesn't really allow you to clearly see that. It just makes the positioned elements harder to read. So I removed it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
box-shadow: 3px 3px 3px rgba(0 0 0 / .2) does the trick - when 3 are on top of each other it's apparent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this, and I've also removed the background color from the positioned elements, so that when they are overlapping, you get a darker box shadow and overlapping text,
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move most of these explanations, made more generic, into the description area values section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to do that. I think they are useful here, explained in the context of the example. It is tricky to understand the effects these values have, so this serves as a useful recap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can keep this here, but add the guts to the description, and make this a summary of what is happening, allowing the explanation to be in the description with a "select the [example of the `all` value](#anchor)" lingo with a link to this example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've had a go at representing the extra information from the example in a more generic fashion inside the description section. It has got quite wordy, and I'm not convinced it is that great. This stuff really is quite complicated to explain. Let me know what you think ;-)
Uh oh!
There was an error while loading. Please reload this page.