-
Notifications
You must be signed in to change notification settings - Fork 700
Добавляет доки про CSS Anchor Positioning, часть 1 #5922
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
Merged
solarrust
merged 17 commits into
doka-guide:main
from
akhmadullin:doka/css-anchor-positioning-1
Jan 20, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e2f13b1
Добавляет доку про свойство anchor-name
akhmadullin bf71bbc
Добавляет доку про свойство position-anchor
akhmadullin 849848d
Добавляет доку про функцию anchor()
akhmadullin fff088d
Добавляет доку про свойство position-area
akhmadullin 25852f3
Добавляет доки в индекс
akhmadullin 7720e88
Правит комментарий в примере кода
akhmadullin 51dd384
Сжимает картинку
akhmadullin 4c7e281
Красит синтаксис кода в демках
akhmadullin d042042
Добавляет точки с запятой в примеры кода в демках
akhmadullin c243558
Добавляет адаптивность демкам
akhmadullin 5871e23
Добавляет supports нотификацию
akhmadullin 82c10d1
Выносит таргет выше подписей top, bottom, right, left
akhmadullin 135842c
Улучшает адаптивность демок
akhmadullin e7cea54
Улучшает адаптивность демок
akhmadullin 3207bba
Делает демки уже
akhmadullin 482da49
Правит подярок блоков в тексте
akhmadullin faad710
Правит текст
akhmadullin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
424 changes: 424 additions & 0 deletions
424
css/anchor-function/demos/anchor-function-inside-outside/index.html
Large diffs are not rendered by default.
Oops, something went wrong.
515 changes: 515 additions & 0 deletions
515
css/anchor-function/demos/anchor-function-top-left/index.html
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| --- | ||
| title: "`anchor()`" | ||
| description: "Позиционируем элемент относительно одной из сторон якоря." | ||
| baseline: | ||
| - group: anchor-positioning | ||
| features: | ||
| - css.properties.top.anchor | ||
| - css.properties.right.anchor | ||
| - css.properties.bottom.anchor | ||
| - css.properties.left.anchor | ||
| - css.properties.left.anchor | ||
| - css.properties.inset-block-end.anchor | ||
| - css.properties.inset-block-start.anchor | ||
| - css.properties.inset-block.anchor | ||
| - css.properties.inset-inline-end.anchor | ||
| - css.properties.inset-inline-start.anchor | ||
| - css.properties.inset-inline.anchor | ||
| - css.properties.inset.anchor | ||
| authors: | ||
| - akhmadullin | ||
| related: | ||
| - css/position | ||
| - css/anchor-name | ||
| - css/position-anchor | ||
| tags: | ||
| - doka | ||
| --- | ||
|
|
||
| ## Кратко | ||
|
|
||
| Функция `anchor()` привязывает таргет элемент к одной из сторон якорного элемента. | ||
|
|
||
| ## Пример | ||
|
|
||
| ```css | ||
| .target { | ||
| top: anchor(bottom); | ||
| } | ||
| ``` | ||
|
|
||
| ## Как пишется | ||
|
|
||
| Функция `anchor()` принимает три аргумента: | ||
|
|
||
| - `<anchor-name>` — имя якоря, относительно которого нужно спозиционировать текущий таргет элемент. Необязятальный аргумент, если его опустить, то функция будет ссылаться на значение указаное в свойстве [`position-anchor`](/css/position-anchor/); | ||
| - `<anchor-side>` — сторона якорного элемента, относительно которой нужно спозиционировать текущий таргет элемент; | ||
| - `<length-percentage>` – фолбэк-значение, применится, если функция не нашла якорный элемент, на который мы пытаемся сослаться, или если передали некорректное значение для `<anchor-side>`. Необязятальный аргумент. | ||
|
|
||
| ```css | ||
| .anchor { | ||
| anchor-name: --my-anchor; | ||
| } | ||
|
|
||
| .target { | ||
| /* | ||
| Функция anchor() будет использовать якорь --my-anchor, | ||
| указанный в свойстве anchor-name, | ||
| поскольку в неё явно не передан никакой другой якорь. | ||
| */ | ||
| top: anchor(bottom); | ||
| /* | ||
| В данном случае функция anchor() будет ссылаться на якорь --custom-anchor. | ||
| Якорь --my-anchor из свойства anchor-name будет проигнорирован. | ||
| */ | ||
| top: anchor(--custom-anchor bottom); | ||
| /* | ||
| В этом примере target элемент будет иметь top: 50%, | ||
| если по каким-то причинам функция anchor() не сможет привязаться | ||
| к указанной стороне переданного якоря. | ||
| */ | ||
| top: anchor(--custom-anchor bottom, 50%); | ||
| } | ||
| ``` | ||
|
|
||
| ## Как понять | ||
|
|
||
| Функция `anchor()` ссылается на параметры позиционирования якорного элемента. Её можно использовать, чтобы расположить таргет элемент в нужном месте относительно якоря. Может быть применена только в [inset-свойствах](/css/inset/). | ||
|
|
||
| Чтобы лучше понять, как функция работает, давайте рассмотрим её работу на примере демки: | ||
|
|
||
| ```css | ||
| .anchor { | ||
| anchor-name: --my-anchor; | ||
| } | ||
|
|
||
| .target { | ||
| position: absolute; | ||
| position-anchor: --my-anchor; | ||
| top: anchor(bottom); | ||
| left: anchor(right); | ||
| } | ||
| ``` | ||
|
|
||
| <iframe title="Позиционируем элемент с помощью функции anchor()" src="demos/anchor-function-top-left/" height="490"></iframe> | ||
|
|
||
| Стоит отметить, что в качестве аргумента `<anchor-side>` в функцию можно передавать только значения, соответствующие оси inset-свойства, для которого функция применяется. | ||
|
|
||
| ```css | ||
| .target { | ||
| /* | ||
| top и bottom находятся в одной оси (вертикальной), | ||
| поэтому следующие две строки будут работать. | ||
| */ | ||
| top: anchor(top); | ||
| top: anchor(bottom); | ||
| /* | ||
| top находится в вертикальной оси, left и right в горизонтальной. | ||
| Оси разные, поэтому строчки ниже работать не будут. | ||
| */ | ||
| top: anchor(left); | ||
| top: anchor(right); | ||
| } | ||
| ``` | ||
|
|
||
| Также при работе с функцией `anchor()` можно использовать процентные значения | ||
|
|
||
| ```css | ||
| .target { | ||
| top: anchor(50%); | ||
| } | ||
| ``` | ||
|
|
||
| использовать её значение в вычислениях | ||
|
|
||
| ```css | ||
| .target { | ||
| top: calc(anchor(bottom) + 10px); | ||
| } | ||
| ``` | ||
|
|
||
| и взаимодействовать с [логическими свойствами](/css/logical-properties/) | ||
|
|
||
| ```css | ||
| .target { | ||
| inset-block-end: anchor(start); | ||
| } | ||
| ``` | ||
|
|
||
| Помимо этого в качестве `<anchor-side>` можно ещё использовать значения `inside`, `outside`: | ||
|
|
||
| - `inside` – соответствует той же самой стороне, для которой применяется функция `anchor()`; | ||
| - `outside` – соответствует противоположной. | ||
|
|
||
| <iframe title="Позиционируем элемент с помощью функции anchor() и значений inside, outside" src="demos/anchor-function-inside-outside/" height="440"></iframe> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| title: "`anchor-name`" | ||
| description: "Объявляет элемент якорным." | ||
| baseline: | ||
| - group: anchor-positioning | ||
| features: | ||
| - css.properties.anchor-name | ||
| - css.properties.anchor-name.none | ||
| authors: | ||
| - akhmadullin | ||
| related: | ||
| - css/position | ||
| - css/position-anchor | ||
| # - css/anchor-scope | ||
| tags: | ||
| - doka | ||
| --- | ||
|
|
||
| ## Кратко | ||
|
|
||
| Свойство `anchor-name` задаёт якорное имя для элемента. | ||
|
|
||
| ## Пример | ||
|
|
||
| ```css | ||
| .anchor { | ||
| anchor-name: --my-anchor; | ||
| } | ||
| ``` | ||
|
|
||
| ## Как пишется | ||
|
|
||
| Возможные значения `anchor-name`: | ||
|
|
||
| - `none` — значение по умолчанию, якорное имя не задаётся; | ||
| - `<anchor-name>` — якорное имя, должно начинаться с двух дефисов. | ||
|
|
||
| ## Как понять | ||
|
|
||
| Свойство `anchor-name` объявляет элемент якорным. Оно задаёт имя, с помощью которого другие элементы могут сослаться на текущий, чтобы спозиционироваться относительно него. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,6 +246,10 @@ groups: | |
| - stacking-context | ||
| - z-index | ||
| - inset | ||
| - anchor-name | ||
| - position-anchor | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Сложил доки в раздел "Позиционирование". Норм или лучше завести отдельный раздел под Anchor Positioning? |
||
| - anchor-function | ||
| - position-area | ||
| - name: 'Списки' | ||
| items: | ||
| - list-style | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| title: "`position-anchor`" | ||
| description: "Задаёт дефолтный якорный элемент." | ||
| baseline: | ||
| - group: anchor-positioning | ||
| features: | ||
| - css.properties.position-anchor | ||
| - css.properties.position-anchor.auto | ||
| authors: | ||
| - akhmadullin | ||
| related: | ||
| - css/position | ||
| - css/anchor-name | ||
| - css/anchor-function | ||
| tags: | ||
| - doka | ||
| --- | ||
|
|
||
| ## Кратко | ||
|
|
||
| Свойство `position-anchor` определяет якорный элемент, к которому должен быть привязан текущий. | ||
|
|
||
| ## Пример | ||
|
|
||
| ```css | ||
| .target { | ||
| position-anchor: --my-anchor; | ||
| } | ||
| ``` | ||
|
|
||
| ## Как пишется | ||
|
|
||
| Возможные значения `position-anchor`: | ||
|
|
||
| - `auto` — значение по умолчанию, дефолтное якорное имя не задаётся; | ||
| - `<anchor-name>` — имя, заданное в свойстве [`anchor-name`](/css/anchor-name/) якорного элемента, должно начинаться с двух дефисов. | ||
|
|
||
| ```css | ||
| .anchor { | ||
| anchor-name: --my-anchor; | ||
| } | ||
|
|
||
| .target { | ||
| position: absolute; | ||
| position-anchor: --my-anchor; | ||
| } | ||
| ``` | ||
|
|
||
| ## Как понять | ||
|
|
||
| Свойство `position-anchor` указывает дефолтный якорный элемент, относительно которого будет позиционироваться текущий. Функции [`anchor()`](/css/anchor-function/) и [`anchor-size()`](/css/anchor-size-function/), отвечающие за расположение и размер текущего элемента, будут использовать значение `position-anchor`, чтобы привязаться к нужному якорному элементу, если в них явно не передать имя другого якоря. | ||
|
|
||
| ## Подсказки | ||
|
|
||
| 💡 Не забудьте указать `position: absolute` или `position: fixed` для таргет элемента, так как [Anchor Positioning](/css/anchor-positioning-guide) работает только с этими видами позиционирования. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.